ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-06-14 07:26:05
Exec Total Coverage
Lines: 2775 8325 33.3%
Functions: 76 290 26.2%
Branches: 2400 7187 33.4%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "dialog/info.h"
11 #include "metadata/metadata.h"
12
13 #include "base/qrs.h"
14 #include "base/dmap.h"
15 #include "base/packfile.h"
16 #include "base/cpool.h"
17 #include "base/autocombo.h"
18 #include "base/gui.h"
19 #include "base/msgstr.h"
20 #include "zc/zelda.h"
21 #include "zq/zq_class.h"
22 #include "zq/zq_misc.h"
23 #include "zq/zquest.h"
24 #include "qst.h"
25 #include "base/colors.h"
26 #include "tiles.h"
27 #include "zq/zquestdat.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "md5.h"
33 #include "zc/zc_custom.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include <fmt/format.h>
47 #include <filesystem>
48
49 #ifdef __EMSCRIPTEN__
50 #include "base/emscripten_utils.h"
51 #endif
52
53 namespace fs = std::filesystem;
54
55 using namespace util;
56 extern FFScript FFCore;
57
58 extern ZModule zcm;
59 extern zcmodule moduledata;
60 extern uint8_t ViewLayer3BG, ViewLayer2BG;
61 extern int32_t LayerDitherBG, LayerDitherSz;
62 extern bool NoHighlightLayer0;
63
64 using std::string;
65 using std::pair;
66 #define EPSILON 0.01 // Define your own tolerance
67 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 9 zmap Map;
80 int32_t prv_mode=0;
81 int16_t ffposx[MAXFFCS];
82 int16_t ffposy[MAXFFCS];
83 int32_t ffprvx[MAXFFCS];
84 int32_t ffprvy[MAXFFCS];
85 void init_ffpos()
86 {
87 for (word q = 0; q < MAXFFCS; ++q)
88 {
89 ffposx[q] = -1000;
90 ffposy[q] = -1000;
91 ffprvx[q] = -10000000;
92 ffprvy[q] = -10000000;
93 }
94 }
95
96 bool save_warn=true;
97
98 int32_t COMBOPOS(int32_t x, int32_t y)
99 {
100 return (((y) & 0xF0) + ((x) >> 4));
101 }
102 int32_t COMBOPOS_B(int32_t x, int32_t y)
103 {
104 if(unsigned(x) >= 256 || unsigned(y) >= 176)
105 return -1;
106 return COMBOPOS(x,y);
107 }
108 int32_t COMBOX(int32_t pos)
109 {
110 return ((pos) % 16 * 16);
111 }
112 int32_t COMBOY(int32_t pos)
113 {
114 return ((pos) & 0xF0);
115 }
116
117 void reset_dmap(int32_t index)
118 {
119 bound(index,0,MAXDMAPS-1);
120 DMaps[index].clear();
121 DMaps[index].title = "";
122 sprintf(DMaps[index].intro, " ");
123 }
124
125 void reset_dmaps()
126 {
127 for(int32_t i=0; i<MAXDMAPS; i++)
128 reset_dmap(i);
129 }
130
131 void truncate_dmap_title(std::string& title)
132 {
133 title.resize(21, ' ');
134 }
135
136 mapscr* zmap::get_prvscr()
137 {
138 return &prvscr;
139 }
140
141
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
142 {
143 18 can_paste=false;
144 18 prv_cmbcycle=0;
145 18 prv_advance=0;
146 18 prv_freeze=0;
147 18 copyffc=-1;
148
149 18 memset(scrpos, 0, sizeof(scrpos));
150 18 screens=NULL;
151 18 prv_time=0;
152 18 prv_scr=0;
153 18 prv_map=0;
154 18 copyscr=0;
155 18 currscr=0;
156 18 copymap=0;
157 18 currmap=0;
158 18 layer_target_map = 0;
159 18 layer_target_scr = 0;
160 18 layer_target_multiple = 0;
161
162 18 }
163 18 zmap::~zmap()
164 {
165 18 }
166
167 9 void zmap::clear()
168 {
169
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
170 9 }
171 void zmap::force_refr_pointer()
172 {
173 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
174 screens = nullptr;
175 else screens = &TheMaps[currmap*MAPSCRS];
176 }
177 bool zmap::CanUndo()
178 {
179 return undo_stack.size() > 0;
180 }
181 bool zmap::CanRedo()
182 {
183 return redo_stack.size() > 0;
184 }
185 bool zmap::CanPaste()
186 {
187 return can_paste;
188 }
189 int32_t zmap::CopyScr()
190 {
191 return (copymap<<8)+copyscr;
192 }
193 int32_t zmap::getCopyFFC()
194 {
195 return copyffc;
196 }
197 set_ffc_command::data_t zmap::getCopyFFCData()
198 {
199 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
200 }
201 29 int32_t zmap::getMapCount()
202 {
203 29 return map_count;
204 }
205 int32_t zmap::getLayerTargetMap()
206 {
207 return layer_target_map;
208 }
209 int32_t zmap::getLayerTargetScr()
210 {
211 return layer_target_scr;
212 }
213 int32_t zmap::getLayerTargetMultiple()
214 {
215 return layer_target_multiple;
216 }
217 bool zmap::isDungeon(int32_t scr)
218 {
219 for(int32_t i=0; i<4; i++)
220 {
221 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
222 {
223 return false;
224 }
225 }
226
227 return true;
228 }
229
230 bool zmap::clearall(bool validate)
231 {
232 Color=0;
233 char tbuf[10];
234
235 if((header.templatepath[0]!=0)&&validate)
236 {
237 if(!valid_zqt(header.templatepath))
238 {
239 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
240 return false;
241 }
242 }
243
244 for(int32_t i=0; i<map_count; i++)
245 {
246 setCurrMap(i);
247 sprintf(tbuf, "%d", i);
248 clearmap(true);
249 }
250
251 setCurrMap(0);
252 return true;
253 }
254
255 bool zmap::reset_templates(bool validate)
256 {
257 //why are we doing this?
258 if(colordata==NULL)
259 {
260 return false;
261 }
262
263 char *deletefilename=(char *)malloc(1);
264 ASSERT(deletefilename);
265 deletefilename[0]=0;
266
267 //int32_t ret;
268 word version, build, dummy, sversion=0;
269 byte dummyc;
270 word dummyw;
271 //int32_t section_size;
272 word temp_map_count;
273 mapscr temp_mapscr;
274 PACKFILE *f=NULL;
275
276 // setPackfilePassword(datapwd);
277 f=open_quest_template(&header, deletefilename, validate);
278 get_version_and_build(f, &version, &build);
279
280 if(!find_section(f, ID_MAPS))
281 {
282 // setPackfilePassword(NULL);
283 return false;
284 }
285
286 //section version info
287 if(!p_igetw(&sversion,f))
288 {
289 return false;
290 }
291
292 if(!p_igetw(&dummy,f))
293 {
294 return false;
295 }
296
297 //section size
298 dword dummy_size;
299 if(!p_igetl(&dummy_size,f))
300 {
301 return false;
302 }
303
304 //finally... section data
305 if(!p_igetw(&temp_map_count,f))
306 {
307 return false;
308 }
309
310 if(version>12)
311 {
312 if(!p_getc(&dummyc,f))
313 return qe_invalid;
314
315 if(!p_getc(&dummyc,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_igetw(&dummyw,f))
328 return qe_invalid;
329
330 if(!p_igetw(&dummyw,f))
331 return qe_invalid;
332
333 if(!p_igetw(&dummyw,f))
334 return qe_invalid;
335
336 if(!p_igetw(&dummyw,f))
337 return qe_invalid;
338
339 if(!p_igetw(&dummyw,f))
340 return qe_invalid;
341
342 if(!p_igetw(&dummyw,f))
343 return qe_invalid;
344
345 if(!p_igetw(&dummyw,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353 }
354
355 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
356 {
357 readmapscreen(f, &header, &temp_mapscr, sversion);
358 }
359
360 readmapscreen(f, &header, &TheMaps[128], sversion);
361 readmapscreen(f, &header, &TheMaps[129], sversion);
362
363 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
364 {
365 readmapscreen(f, &header, &temp_mapscr, sversion);
366 }
367
368 if(version>12)
369 {
370 if(!p_getc(&dummyc,f))
371 return qe_invalid;
372
373 if(!p_getc(&dummyc,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_igetw(&dummyw,f))
386 return qe_invalid;
387
388 if(!p_igetw(&dummyw,f))
389 return qe_invalid;
390
391 if(!p_igetw(&dummyw,f))
392 return qe_invalid;
393
394 if(!p_igetw(&dummyw,f))
395 return qe_invalid;
396
397 if(!p_igetw(&dummyw,f))
398 return qe_invalid;
399
400 if(!p_igetw(&dummyw,f))
401 return qe_invalid;
402
403 if(!p_igetw(&dummyw,f))
404 return qe_invalid;
405
406 if(!p_getc(&dummyc,f))
407 return qe_invalid;
408
409 if(!p_getc(&dummyc,f))
410 return qe_invalid;
411 }
412
413 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
414 {
415 readmapscreen(f, &header, &temp_mapscr, sversion);
416 }
417
418 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
420
421 pack_fclose(f);
422 clear_quest_tmpfile();
423
424 if(deletefilename[0]==0)
425 {
426 delete_file(deletefilename);
427 }
428
429 // setPackfilePassword(NULL);
430
431 return true;
432 }
433
434 bool zmap::clearmap(bool newquest)
435 {
436 if(currmap<map_count)
437 {
438 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
439 {
440 clearscr(i);
441 }
442
443 setCurrScr(0);
444
445 if(newquest)
446 {
447 if(!reset_templates(false))
448 {
449 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
450 }
451 }
452 }
453
454 return true;
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+currscr;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::AbsoluteScr(int32_t scr)
466 {
467 if(unsigned(scr) >= MAPSCRS*getMapCount())
468 return nullptr;
469 return &TheMaps[scr];
470 }
471 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
472 {
473 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
474 return nullptr;
475 return AbsoluteScr((map*MAPSCRS)+scr);
476 }
477 void zmap::set_prvscr(int32_t map, int32_t scr)
478 {
479 prvscr=TheMaps[(map*MAPSCRS)+scr];
480
481 for(int32_t i=0; i<6; i++)
482 {
483 if(prvscr.layermap[i]>0)
484 {
485 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
486 }
487 else
488 prvlayers[i].valid = 0;
489 }
490
491 prv_map=map;
492 prv_scr=scr;
493 }
494 71 int32_t zmap::getCurrMap()
495 {
496 71 return currmap;
497 }
498 bool zmap::isDark()
499 {
500 return (screens[currscr].flags&fDARK)!=0;
501 }
502
503 void zmap::setCurrentView(int32_t map, int32_t scr)
504 {
505 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
506 if (map != Map.getCurrMap()) Map.setCurrMap(map);
507 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
508 if (change_view)
509 {
510 refresh(rALL);
511 rebuild_trans_table();
512 }
513 }
514
515 9 void zmap::setCurrMap(int32_t index)
516 {
517 9 int32_t oldmap=currmap;
518 9 optional<int> oldcolor;
519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
520 oldcolor = getcolor();
521 9 scrpos[currmap]=currscr;
522 9 currmap=bound(index,0,map_count);
523 9 screens=&TheMaps[currmap*MAPSCRS];
524
525 9 currscr=scrpos[currmap];
526 9 int newcolor = getcolor();
527 9 loadlvlpal(newcolor);
528
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
529 9 rebuild_trans_table();
530
531 9 reset_combo_animations2();
532 9 mmap_mark_dirty();
533 9 }
534
535 17 int32_t zmap::getCurrScr()
536 {
537 17 return currscr;
538 }
539 9 void zmap::setCurrScr(int32_t scr)
540 {
541
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
542
543 8 int32_t oldscr=currscr;
544 8 int32_t oldcolor=getcolor();
545
546
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
547 {
548 2 oldcolor=-1;
549 2 }
550
551 8 currscr=bound(scr,0,MAPSCRS-1);
552 8 int32_t newcolor=getcolor();
553 8 loadlvlpal(newcolor);
554
555 //setcolor(newcolor);
556
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
557 {
558 newcolor=-1;
559 }
560
561
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
562 {
563 7 rebuild_trans_table();
564 7 }
565
566 8 reset_combo_animations2();
567 8 setlayertarget();
568 8 mmap_mark_dirty();
569 9 }
570
571 8 void zmap::setlayertarget()
572 {
573 8 layer_target_map = 0;
574 8 layer_target_multiple = 0;
575
576
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
577 {
578
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
579 {
580 2856 int32_t i=(m*MAPSCRS+s);
581 2856 mapscr *ts=&TheMaps[i];
582
583 // Search through each layer
584
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
585 {
586
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
587 {
588 if(layer_target_map > 0)
589 {
590 layer_target_multiple += 1;
591 continue;
592 }
593
594 layer_target_map = m+1;
595 layer_target_scr = s;
596 }
597 17136 }
598 2856 }
599 21 }
600 8 }
601
602 void zmap::setcolor(int32_t c)
603 {
604 screens[currscr].valid |= mVALID;
605 screens[currscr].color = c;
606
607 if(Color!=c)
608 {
609 Color = c;
610 loadlvlpal(c);
611 rebuild_trans_table();
612 }
613
614 mmap_mark_dirty();
615 }
616
617 25 int32_t zmap::getcolor()
618 {
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
620 {
621 return prvscr.color;
622 }
623
624 25 return screens[currscr].color;
625 25 }
626
627 void zmap::resetflags()
628 {
629 byte *di=&(screens[currscr].valid);
630
631 for(int32_t i=1; i<48; i++)
632 {
633 *(di+i)=0;
634 }
635 }
636
637 word zmap::tcmbdat(int32_t pos)
638 {
639 return screens[TEMPLATE].data[pos];
640 }
641
642 word zmap::tcmbcset(int32_t pos)
643 {
644 return screens[TEMPLATE].cset[pos];
645 }
646
647 int32_t zmap::tcmbflag(int32_t pos)
648 {
649 return screens[TEMPLATE].sflag[pos];
650 }
651
652 word zmap::tcmbdat2(int32_t pos)
653 {
654 return screens[TEMPLATE2].data[pos];
655 }
656
657 word zmap::tcmbcset2(int32_t pos)
658 {
659 return screens[TEMPLATE2].cset[pos];
660 }
661
662 int32_t zmap::tcmbflag2(int32_t pos)
663 {
664 return screens[TEMPLATE2].sflag[pos];
665 }
666
667 void zmap::TemplateAll()
668 {
669 StartListCommand();
670 for(int32_t i=0; i<128; i++)
671 {
672 if((screens[i].valid&mVALID) && isDungeon(i))
673 DoTemplateCommand(-1, i, currscr);
674 }
675 FinishListCommand();
676 }
677
678 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
679 {
680 if(scr==TEMPLATE)
681 return;
682
683 if(!(screens[scr].valid&mVALID))
684 screens[scr].color=Color;
685
686 screens[scr].valid|=mVALID;
687
688 for(int32_t i=0; i<32; i++)
689 {
690 screens[scr].data[i]=screens[TEMPLATE].data[i];
691 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
692 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
693 }
694
695 for(int32_t i=144; i<176; i++)
696 {
697 screens[scr].data[i]=screens[TEMPLATE].data[i];
698 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
699 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
700 }
701
702 for(int32_t y=2; y<=9; y++)
703 {
704 int32_t j=y<<4;
705 screens[scr].data[j]=screens[TEMPLATE].data[j];
706 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
707 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
708 ++j;
709 screens[scr].data[j]=screens[TEMPLATE].data[j];
710 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
711 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
712 ++j;
713 j+=12;
714 screens[scr].data[j]=screens[TEMPLATE].data[j];
715 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
716 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
717 ++j;
718 screens[scr].data[j]=screens[TEMPLATE].data[j];
719 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
720
721 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
722 ++j;
723 }
724
725 if(floorcombo!=-1)
726 {
727 for(int32_t y=2; y<9; y++)
728 for(int32_t x=2; x<14; x++)
729 {
730 int32_t i=(y<<4)+x;
731 screens[scr].data[i] = floorcombo;
732 screens[scr].cset[i] = floorcset;
733 }
734 }
735
736 for(int32_t i=0; i<4; i++)
737 putdoor(scr,i,screens[scr].door[i]);
738 }
739
740
741 void zmap::clearscr(int32_t scr)
742 {
743 screens[scr].zero_memory();
744 screens[scr].valid=mVERSION;
745 for(int q = 0; q < 6; ++q)
746 {
747 auto layer = map_autolayers[currmap*6+q];
748 screens[scr].layermap[q] = layer;
749 screens[scr].layerscreen[q] = layer ? scr : 0;
750 }
751 mmap_mark_dirty();
752 }
753
754 const char *loaderror[] =
755 {
756
757 "OK","File not found","Incomplete data",
758 "Invalid version","Invalid file"
759
760 };
761
762 int32_t zmap::load(const char *path)
763 {
764 PACKFILE *f=pack_fopen_password(path,F_READ, "");
765
766 if(!f)
767 return 1;
768
769
770 int16_t version;
771 byte build;
772
773 //get the version
774 if(!p_igetw(&version,f))
775 {
776 goto file_error;
777 }
778
779 //get the build
780 if(!p_getc(&build,f))
781 {
782 goto file_error;
783 }
784
785 for(int32_t i=0; i<MAPSCRS; i++)
786 {
787 mapscr tmpimportscr;
788 tmpimportscr.zero_memory();
789 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
790 {
791 al_trace("failed zmap::load\n");
792 goto file_error;
793 }
794
795 switch(ImportMapBias)
796 {
797 case 0:
798 *(screens+i) = tmpimportscr;
799 break;
800
801 case 1:
802 if(!(screens[i].valid&mVALID))
803 {
804 *(screens+i) = tmpimportscr;
805 }
806 break;
807
808 case 2:
809 if(tmpimportscr.valid&mVALID)
810 {
811 *(screens+i) = tmpimportscr;
812 }
813 break;
814 }
815 }
816
817
818 pack_fclose(f);
819
820 setCurrScr(0);
821 mmap_mark_dirty();
822 return 0;
823
824 file_error:
825 pack_fclose(f);
826 clearmap(false);
827 return 2;
828 }
829
830 int32_t zmap::save(const char *path)
831 {
832 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
833
834 if(!f)
835 return 1;
836
837 if(!p_iputw(V_MAPS,f))
838 {
839 pack_fclose(f);
840 return 3;
841 }
842
843 // This was the "build number", but that's totally useless here. Keep this junk byte
844 // so as not to totally break exports between ZC versions.
845 if(!p_putc(0,f))
846 {
847 pack_fclose(f);
848 return 3;
849 }
850
851 for(int32_t i=0; i<MAPSCRS; i++)
852 {
853 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
854 {
855 pack_fclose(f);
856 return 2;
857 }
858 }
859
860 pack_fclose(f);
861 return 0;
862 }
863
864
865 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
866 {
867 // Hookshots can be blocked by solid combos on all 3 ground layers.
868 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
869
870 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
871 return true;
872 if (c->walk&(1<<i))
873 return false;
874
875 for(int32_t k=0; k<2; k++)
876 {
877 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
878
879 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
880 {
881 return false;
882 }
883 }
884
885 return true;
886 }
887
888 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
889 {
890 // Hookshots can be blocked by solid combos on all 3 ground layers.
891 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
892
893 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
894 return true;
895 if (c->walk&(1<<i))
896 return false;
897
898 for(int32_t k=0; k<2; k++)
899 {
900 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
901
902 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
903 {
904 return false;
905 }
906 }
907
908 return true;
909 }
910
911 bool zmap::isstepable(int32_t combo)
912 {
913 // This is kind of odd but it's true to the engine (see maps.cpp)
914 return (combo_class_buf[combobuf[combo].type].ladder_pass);
915 }
916
917 // Returns the letter of the warp combo.
918 int32_t zmap::warpindex(int32_t combo)
919 {
920 switch(combobuf[combo].type)
921 {
922 case cCAVE:
923 case cPIT:
924 case cSTAIR:
925 case cCAVE2:
926 case cSWIMWARP:
927 case cDIVEWARP:
928 case cSWARPA:
929 return 0;
930
931 case cCAVEB:
932 case cPITB:
933 case cSTAIRB:
934 case cCAVE2B:
935 case cSWIMWARPB:
936 case cDIVEWARPB:
937 case cSWARPB:
938 return 1;
939
940 case cCAVEC:
941 case cPITC:
942 case cSTAIRC:
943 case cCAVE2C:
944 case cSWIMWARPC:
945 case cDIVEWARPC:
946 case cSWARPC:
947 return 2;
948
949 case cCAVED:
950 case cPITD:
951 case cSTAIRD:
952 case cCAVE2D:
953 case cSWIMWARPD:
954 case cDIVEWARPD:
955 case cSWARPD:
956 return 3;
957
958 case cPITR:
959 case cSTAIRR:
960 case cSWARPR:
961 return 4;
962 }
963
964 return -1;
965
966 }
967
968 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
969 {
970 if(top)
971 line(dest,x,y,x+15,y,c);
972 rectfill(dest,x,y,x+3,y+15,c);
973 rectfill(dest,x+12,y,x+15,y+15,c);
974 rectfill(dest,x+4,y+2,x+11,y+5,c);
975 rectfill(dest,x+4,y+10,x+11,y+13,c);
976 }
977
978 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
979 {
980 line(dest,x,y,x+15,y,c);
981 }
982
983 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
984 {
985 int32_t cx = COMBOX(pos);
986 int32_t cy = COMBOY(pos);
987
988 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
989
990 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
991
992 int32_t bridgedetected = 0;
993
994 for(int32_t i=0; i<4; i++)
995 {
996 int32_t tx=((i&2)<<2)+x;
997 int32_t ty=((i&1)<<3)+y;
998 int32_t tx2=((i&2)<<2)+cx;
999 int32_t ty2=((i&1)<<3)+cy;
1000 for (int32_t m = layer; m <= 1; m++)
1001 {
1002 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1003 {
1004 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1005 {
1006 bridgedetected |= (1<<i);
1007 }
1008 }
1009 else
1010 {
1011 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1012 {
1013 bridgedetected |= (1<<i);
1014 }
1015 }
1016 }
1017 if (bridgedetected & (1<<i))
1018 {
1019 if (i >= 3) break;
1020 else continue;
1021 }
1022 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1023 {
1024 for(int32_t k=0; k<8; k+=2)
1025 for(int32_t j=0; j<8; j+=2)
1026 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1027 }
1028 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1029 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1030
1031 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1032 {
1033 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1034 {
1035 for(int32_t k=0; k<8; k+=2)
1036 for(int32_t j=0; j<8; j+=2)
1037 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1038 }
1039 else
1040 {
1041 int32_t color = COLOR_SOLID;
1042
1043 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1044 color=vc(6);
1045 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1046 color=vc(7);
1047
1048 rectfill(dest,tx,ty,tx+7,ty+7,color);
1049 }
1050 }
1051 }
1052
1053 bridgedetected = 0;
1054 for(int32_t i=0; i<4; i++)
1055 {
1056 int32_t tx2=((i&2)<<2)+cx;
1057 int32_t ty2=((i&1)<<3)+cy;
1058 for (int32_t m = 0; m <= 1; m++)
1059 {
1060 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1061 {
1062 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1063 {
1064 bridgedetected |= (1<<i);
1065 }
1066 }
1067 else
1068 {
1069 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1070 {
1071 bridgedetected |= (1<<i);
1072 }
1073 }
1074 }
1075 }
1076
1077 // Draw damage combos
1078 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1079 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1080 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1081 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1082 || combo_class_buf[c1.type].modify_hp_amount
1083 || combo_class_buf[c2.type].modify_hp_amount;
1084
1085 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1086
1087 if(dmg)
1088 {
1089 if (bridgedetected <= 0)
1090 {
1091 for(int32_t k=0; k<16; k+=2)
1092 for(int32_t j=0; j<16; j+=2)
1093 if(((k+j)/2)%2)
1094 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1095 }
1096 else
1097 {
1098 for(int32_t i=0; i<4; i++)
1099 {
1100 if (!(bridgedetected & (1<<i)))
1101 {
1102 int32_t tx=((i&2)<<2)+x;
1103 int32_t ty=((i&1)<<3)+y;
1104 for(int32_t k=0; k<8; k+=2)
1105 for(int32_t j=0; j<8; j+=2)
1106 if(((k+j)/2)%2)
1107 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1108 }
1109 }
1110 }
1111 }
1112
1113 if(c.type == cSLOPE)
1114 {
1115 slope_info s(c, x, y);
1116 s.draw(dest, 0, 0, COLOR_SLOPE);
1117 }
1118 auto fl0 = MAPFLAG2(-1,cx,cy);
1119 auto fl1 = MAPFLAG2(0,cx,cy);
1120 auto fl2 = MAPFLAG2(1,cx,cy);
1121 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1122 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1123 {
1124 bool top = false;
1125 if(cy)
1126 {
1127 top = true;
1128 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1131 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1133 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1134 {
1135 top = false;
1136 }
1137 }
1138 draw_ladder(dest,x,y,COLOR_LADDER,top);
1139 }
1140 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1141 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1142 {
1143 draw_platform(dest,x,y,COLOR_LADDER);
1144 }
1145 }
1146
1147 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1148 {
1149 int32_t cx = COMBOX(pos);
1150 int32_t cy = COMBOY(pos);
1151
1152 if (screen < 0) return;
1153 if (map < 0) return;
1154
1155 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1156
1157 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1158
1159 int32_t bridgedetected = 0;
1160 for(int32_t i=0; i<4; i++)
1161 {
1162 int32_t tx=((i&2)<<2)+x;
1163 int32_t ty=((i&1)<<3)+y;
1164 int32_t tx2=((i&2)<<2)+cx;
1165 int32_t ty2=((i&1)<<3)+cy;
1166 for (int32_t m = layer; m <= 1; m++)
1167 {
1168 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1169 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1170 {
1171 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1172 {
1173 bridgedetected |= (1<<i);
1174 }
1175 }
1176 else
1177 {
1178 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1179 {
1180 bridgedetected |= (1<<i);
1181 }
1182 }
1183 }
1184 if (bridgedetected & (1<<i))
1185 {
1186 continue;
1187 }
1188 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1189 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1190
1191
1192 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1193 {
1194 for(int32_t k=0; k<8; k+=2)
1195 for(int32_t j=0; j<8; j+=2)
1196 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1197 }
1198 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1199 {
1200 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1201 {
1202 for(int32_t k=0; k<8; k+=2)
1203 for(int32_t j=0; j<8; j+=2)
1204 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1205 }
1206 else
1207 {
1208 int32_t color = COLOR_SOLID;
1209
1210 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1211 color=vc(6);
1212 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1213 color=vc(7);
1214
1215 rectfill(dest,tx,ty,tx+7,ty+7,color);
1216 }
1217 }
1218 }
1219
1220 bridgedetected = 0;
1221 for(int32_t i=0; i<4; i++)
1222 {
1223 int32_t tx2=((i&2)<<2)+cx;
1224 int32_t ty2=((i&1)<<3)+cy;
1225 for (int32_t m = 0; m <= 1; m++)
1226 {
1227 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1228 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1229 {
1230 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1231 {
1232 bridgedetected |= (1<<i);
1233 }
1234 }
1235 else
1236 {
1237 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1238 {
1239 bridgedetected |= (1<<i);
1240 }
1241 }
1242 }
1243 }
1244
1245 // Draw damage combos
1246 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1247 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1248 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1249 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1250 || combo_class_buf[c1.type].modify_hp_amount
1251 || combo_class_buf[c2.type].modify_hp_amount;
1252
1253 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1254
1255 if(dmg)
1256 {
1257 if (bridgedetected <= 0)
1258 {
1259 for(int32_t k=0; k<16; k+=2)
1260 for(int32_t j=0; j<16; j+=2)
1261 if(((k+j)/2)%2)
1262 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1263 }
1264 else
1265 {
1266 for(int32_t i=0; i<4; i++)
1267 {
1268 if (!(bridgedetected & (1<<i)))
1269 {
1270 int32_t tx=((i&2)<<2)+x;
1271 int32_t ty=((i&1)<<3)+y;
1272 for(int32_t k=0; k<8; k+=2)
1273 for(int32_t j=0; j<8; j+=2)
1274 if(((k+j)/2)%2)
1275 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1276 }
1277 }
1278 }
1279 }
1280
1281 if(c.type == cSLOPE)
1282 {
1283 slope_info s(c, x, y);
1284 s.draw(dest, 0, 0, COLOR_SLOPE);
1285 }
1286 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1287 auto fl1 = MAPFLAG3(map,screen,0,pos);
1288 auto fl2 = MAPFLAG3(map,screen,1,pos);
1289 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1290 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1291 {
1292 bool top = false;
1293 if(cy)
1294 {
1295 top = true;
1296 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1301 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1302 {
1303 top = false;
1304 }
1305 }
1306 draw_ladder(dest,x,y,COLOR_LADDER,top);
1307 }
1308 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1309 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1310 {
1311 draw_platform(dest,x,y,COLOR_LADDER);
1312 }
1313 }
1314
1315 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1316 {
1317 const newcombo& c = combobuf[cmbdat];
1318
1319 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1320
1321 for(int32_t i=0; i<4; i++)
1322 {
1323 int32_t tx=((i&2)<<2)+x;
1324 int32_t ty=((i&1)<<3)+y;
1325
1326 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1327 {
1328 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1329 {
1330 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1331 //al_trace("water, drown\n");
1332 }
1333 else
1334 {
1335 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1336 //al_trace("water, no drown\n");
1337 }
1338 }
1339
1340
1341 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1342 {
1343 for(int32_t k=0; k<8; k+=2)
1344 for(int32_t j=0; j<8; j+=2)
1345 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1346 }
1347 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1348 {
1349 if(c.type==cLADDERHOOKSHOT)
1350 {
1351 for(int32_t k=0; k<8; k+=2)
1352 for(int32_t j=0; j<8; j+=2)
1353 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1354 }
1355 else
1356 {
1357 int32_t color = COLOR_SOLID;
1358
1359 if(c.type==cLADDERONLY)
1360 color=vc(6);
1361 else if(c.type==cHOOKSHOTONLY)
1362 color=vc(7);
1363
1364 rectfill(dest,tx,ty,tx+7,ty+7,color);
1365 }
1366 }
1367
1368 // Draw damage combos
1369 if(combo_class_buf[c.type].modify_hp_amount != 0)
1370 {
1371 for(int32_t k=0; k<8; k+=2)
1372 for(int32_t j=0; j<8; j+=2)
1373 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1374 }
1375 }
1376
1377 if(c.type == cSLOPE)
1378 {
1379 slope_info s(c, 0, 0);
1380 zfix const& slope = s.slope();
1381
1382 BITMAP* sub = create_bitmap_ex(8,16,16);
1383 clear_bitmap(sub);
1384 s.draw(sub, 0, 0, COLOR_SLOPE);
1385 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1386 destroy_bitmap(sub);
1387 }
1388 if(c.flag == mfSIDEVIEWLADDER)
1389 {
1390 draw_ladder(dest,x,y,COLOR_LADDER);
1391 }
1392 else if(c.flag == mfSIDEVIEWPLATFORM)
1393 {
1394 draw_platform(dest,x,y,COLOR_LADDER);
1395 }
1396 }
1397
1398 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1399 {
1400 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1401 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1402 }
1403 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1404 {
1405
1406 newcombo const& c = combobuf[cmbdat];
1407
1408 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1409 {
1410 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1411 // text_mode(-1);
1412 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1413 if(sflag)
1414 {
1415 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1416 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1417 }
1418
1419 if(c.flag)
1420 {
1421 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1422 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1423 }
1424 }
1425
1426 if(flags&cCSET)
1427 {
1428 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1429 // text_mode(inv?vc(15):vc(0));
1430 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1431 }
1432 else if(flags&cCTYPE)
1433 {
1434 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1435 // text_mode(inv?vc(15):vc(0));
1436 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1437 }
1438 }
1439
1440 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1441 {
1442 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1443
1444 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1445 if(repos)
1446 {
1447 combotile_override_x = x+(8*(scale-1));
1448 combotile_override_y = y+(8*(scale-1));
1449 }
1450 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1451 if(repos) combotile_override_x = combotile_override_y = -1;
1452 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1453 destroy_bitmap(b);
1454 }
1455 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1456 {
1457 static newcombo nilcombo;
1458 nilcombo.tile = 0;
1459
1460 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1461
1462 if(c.tile==0)
1463 {
1464 rectfill(dest,x,y,x+15,y+15,vc(0));
1465 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1466 return;
1467 }
1468
1469 putcombo(dest,x,y,cmbdat,cset);
1470
1471 /* moved to put_walkflags
1472 for(int32_t i=0; i<4; i++) {
1473
1474 int32_t tx=((i&2)<<2)+x;
1475 int32_t ty=((i&1)<<3)+y;
1476 if((flags&cWALK) && (c.walk&(1<<i)))
1477 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1478 }
1479 */
1480
1481 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1482 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1483 {
1484 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1485 // text_mode(-1);
1486 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1487 if(sflag)
1488 {
1489 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1490 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1491 }
1492
1493 if(combobuf[cmbdat].flag)
1494 {
1495 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1496 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1497 }
1498 }
1499
1500 if(flags&cWALK)
1501 {
1502 put_walkflags(dest,x,y,cmbdat,0);
1503 }
1504
1505 if(flags&cCSET)
1506 {
1507 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1508 // text_mode(inv?vc(15):vc(0));
1509 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1510 }
1511 else if(flags&cCTYPE)
1512 {
1513 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1514 // text_mode(inv?vc(15):vc(0));
1515 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1516 }
1517 }
1518 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1519 {
1520 auto blitx = 1 + (slot % 16) * 17;
1521 auto blity = 1 + (slot / 16) * 17;
1522 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1523 }
1524
1525
1526 void copy_mapscr(mapscr *dest, const mapscr *src)
1527 {
1528 if(!dest || !src) return;
1529 *dest = *src;
1530 }
1531
1532 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1533 {
1534 int32_t x=0,y=0;
1535 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1536
1537 switch(side)
1538 {
1539 case up:
1540 case down:
1541 x=((pos&15)<<4)+xofs;
1542 y=(ignorepos?0:(pos&0xF0))+yofs;
1543 break;
1544
1545 case left:
1546 case right:
1547 x=(ignorepos?0:((pos&15)<<4))+xofs;
1548 y=(pos&0xF0)+yofs;
1549 break;
1550 }
1551
1552 switch(type)
1553 {
1554 case dt_lock:
1555 case dt_shut:
1556 case dt_boss:
1557 case dt_bomb:
1558 switch(side)
1559 {
1560 case up:
1561 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1562 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1563 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1564 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1565 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1566 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1567 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1568 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1569 break;
1570
1571 case down:
1572 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1573 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1574 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1575 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1576 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1577 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1578 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1579 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1580 break;
1581
1582 case left:
1583 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1584 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1585 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1586 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1587 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1588 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1589
1590 if(x+16 >= dest->w)
1591 break;
1592
1593 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1594 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1595 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1596 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1597 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1598 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1599 break;
1600
1601 case right:
1602
1603 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1604 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1605 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1606 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1607 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1608 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1609
1610 if(x+16 <= 0)
1611 break;
1612
1613 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1614 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1615 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1616 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1617 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1618 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1619 break;
1620 }
1621
1622 break;
1623
1624 case dt_pass:
1625 case dt_wall:
1626 case dt_walk:
1627 default:
1628 break;
1629 }
1630 }
1631
1632 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1633 {
1634 int32_t x=((pos&15)<<4)+xofs;
1635 int32_t y=(pos&0xF0)+yofs;
1636 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1637
1638
1639 switch(side)
1640 {
1641 case up:
1642 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1643 {
1644 overcombo(dest,x,y,
1645 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1646 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1647 }
1648
1649 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1650 {
1651 overcombo(dest,x+16,y,
1652 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1653
1654 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1655 }
1656
1657 break;
1658
1659 case down:
1660 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1661 {
1662 overcombo(dest,x,y,
1663 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1664 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1665 }
1666
1667 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1668 {
1669 overcombo(dest,x+16,y,
1670 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1671 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1672 }
1673
1674 break;
1675
1676 case left:
1677 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1678 {
1679 overcombo(dest,x,y,
1680 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1681 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1682 }
1683
1684 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1685 {
1686 overcombo(dest,x,y+16,
1687 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1688 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1689 }
1690
1691 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1692 {
1693 overcombo(dest,x,y+32,
1694 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1695 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1696 }
1697
1698 break;
1699
1700 case right:
1701 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1702 {
1703 overcombo(dest,x,y,
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1705 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1706 }
1707
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1709 {
1710 overcombo(dest,x,y+16,
1711
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1714 }
1715
1716 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1717 {
1718 overcombo(dest,x,y+32,
1719 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1721 }
1722
1723 break;
1724 }
1725 }
1726
1727 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1728 {
1729 word cmbcheck1, cmbcheck2;
1730 newcombo combocheck1, combocheck2;
1731 combocheck1 = combobuf[0];
1732 combocheck2 = combobuf[0];
1733 combocheck1.walk = 0;
1734 combocheck2.walk = 0;
1735
1736 int32_t layermap, layerscreen;
1737
1738 switch(dir)
1739 {
1740 case up:
1741 {
1742 if(i>15) //not top row of combos
1743 {
1744 return false;
1745 }
1746
1747 if(scr<16) //top row of screens
1748 {
1749 return false;
1750
1751 }
1752
1753 //check main screen
1754 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1755 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1756 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1757 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1758
1759 //check layer 1
1760 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1761
1762 if(layermap>-1 && layermap<map_count)
1763 {
1764 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1765 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1766 if (combobuf[cmbcheck1].type == cBRIDGE)
1767 {
1768 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1769 {
1770 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1771 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1772 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1773 }
1774 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1775 }
1776 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1777 }
1778
1779 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1780
1781 if(layermap>-1 && layermap<map_count)
1782 {
1783 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1784 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1785 if (combobuf[cmbcheck2].type == cBRIDGE)
1786 {
1787 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1788 {
1789 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1790 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1791 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1792 }
1793 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1794 }
1795 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1796 }
1797
1798 //check layer 2
1799 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1800
1801 if(layermap>-1 && layermap<map_count)
1802 {
1803 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1804
1805 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1806 if (combobuf[cmbcheck2].type == cBRIDGE)
1807 {
1808 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1809 {
1810 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1811 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1812 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1813 }
1814 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1815 }
1816 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1817 }
1818
1819 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1820
1821 if(layermap>-1 && layermap<map_count)
1822 {
1823 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1824 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1825 if (combobuf[cmbcheck2].type == cBRIDGE)
1826 {
1827 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1828 {
1829 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1830 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1831 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1832 }
1833 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1834 }
1835 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1836 }
1837
1838 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1839 {
1840 return true;
1841 }
1842
1843 break;
1844 }
1845 case down:
1846 {
1847 if(i<160) //not bottom row of combos
1848 {
1849 return false;
1850 }
1851
1852 if(scr>111) //bottom row of screens
1853 {
1854 return false;
1855 }
1856
1857 //check main screen
1858 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1859 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1860 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1861 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1862
1863
1864 //check layer 1
1865 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1866
1867 if(layermap>-1 && layermap<map_count)
1868 {
1869 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1870 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1871 if (combobuf[cmbcheck1].type == cBRIDGE)
1872 {
1873 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1874 {
1875 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1876 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1877 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1878 }
1879 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1880 }
1881 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1882 }
1883
1884 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1885
1886 if(layermap>-1 && layermap<map_count)
1887 {
1888 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1889 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1890 if (combobuf[cmbcheck2].type == cBRIDGE)
1891 {
1892 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1893 {
1894 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1895 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1896 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1897 }
1898 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1899 }
1900 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1901 }
1902
1903 //check layer 2
1904 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1905
1906 if(layermap>-1 && layermap<map_count)
1907 {
1908 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1909 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1910 if (combobuf[cmbcheck1].type == cBRIDGE)
1911 {
1912 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1913 {
1914 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1915 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1916 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1917 }
1918 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1919 }
1920 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1921 }
1922
1923 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1924
1925 if(layermap>-1 && layermap<map_count)
1926 {
1927 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1928 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1929 if (combobuf[cmbcheck2].type == cBRIDGE)
1930 {
1931 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1932 {
1933 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1934 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1935 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1936 }
1937 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1938 }
1939 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1940 }
1941
1942 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1943 {
1944 return true;
1945 }
1946
1947 break;
1948 }
1949 case left:
1950 {
1951 if((i&0xF)!=0) //not left column of combos
1952 {
1953 return false;
1954 }
1955
1956 if((scr&0xF)==0) //left column of screens
1957 {
1958 return false;
1959 }
1960
1961 //check main screen
1962 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1963 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1964 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1965 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1966
1967 //check layer 1
1968 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1969
1970 if(layermap>-1 && layermap<map_count)
1971 {
1972 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1973 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1974 if (combobuf[cmbcheck1].type == cBRIDGE)
1975 {
1976 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1977 {
1978 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1979 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1980 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1981 }
1982 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1983 }
1984 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1985 }
1986
1987 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1988
1989 if(layermap>-1 && layermap<map_count)
1990 {
1991 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1992 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1993 if (combobuf[cmbcheck2].type == cBRIDGE)
1994 {
1995 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1996 {
1997 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1998 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1999 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2000 }
2001 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2002 }
2003 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2004 }
2005
2006 //check layer 2
2007 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2008
2009 if(layermap>-1 && layermap<map_count)
2010 {
2011 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2012 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2013 if (combobuf[cmbcheck1].type == cBRIDGE)
2014 {
2015 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2016 {
2017 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2018 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2019 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2020 }
2021 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2022 }
2023 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2024 }
2025
2026 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2027
2028 if(layermap>-1 && layermap<map_count)
2029 {
2030 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2031 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2032 if (combobuf[cmbcheck2].type == cBRIDGE)
2033 {
2034 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2035 {
2036 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2037 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2038 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2039 }
2040 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2041 }
2042 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2043 }
2044
2045 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2046 {
2047 return true;
2048 }
2049
2050 break;
2051 }
2052 case right:
2053 {
2054 if((i&0xF)!=15) //not right column of combos
2055 {
2056 return false;
2057 }
2058
2059 if((scr&0xF)==15) //right column of screens
2060 {
2061 return false;
2062 }
2063
2064 //check main screen
2065 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2066 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2067 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2068 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2069
2070 //check layer 1
2071 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2072
2073 if(layermap>-1 && layermap<map_count)
2074 {
2075 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2076 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2077 if (combobuf[cmbcheck1].type == cBRIDGE)
2078 {
2079 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2080 {
2081 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2082 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2083 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2084 }
2085 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2086 }
2087 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2088 }
2089
2090 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2091
2092 if(layermap>-1 && layermap<map_count)
2093 {
2094 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2095 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2096 if (combobuf[cmbcheck2].type == cBRIDGE)
2097 {
2098 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2099 {
2100 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2101 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2102 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2103 }
2104 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2105 }
2106 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2107 }
2108
2109 //check layer 2
2110 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2111
2112 if(layermap>-1 && layermap<map_count)
2113 {
2114 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2115 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2116 if (combobuf[cmbcheck1].type == cBRIDGE)
2117 {
2118 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2119 {
2120 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2121 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2122 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2123 }
2124 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2125 }
2126 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2127 }
2128
2129 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2130
2131 if(layermap>-1 && layermap<map_count)
2132 {
2133 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2134
2135 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2136 if (combobuf[cmbcheck2].type == cBRIDGE)
2137 {
2138 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2139 {
2140 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2141 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2142 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2143 }
2144 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2145 }
2146 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2147 }
2148
2149 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2150 {
2151 return true;
2152 }
2153
2154 break;
2155 }
2156 }
2157
2158 return false;
2159 }
2160
2161 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2162 {
2163 int32_t checkcombo;
2164
2165 if(alignment_arrow_timer>31)
2166 {
2167 if(scr<0)
2168 {
2169 scr=currscr;
2170 }
2171
2172 if((scr<128)) //do the misalignment arrows
2173 {
2174 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2175 {
2176 if(misaligned(currmap, scr, checkcombo, up))
2177 {
2178 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2179 }
2180 }
2181
2182 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2183 {
2184 if(misaligned(currmap, scr, checkcombo, down))
2185 {
2186 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2187 }
2188 }
2189
2190 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2191 {
2192 if(misaligned(currmap, scr, checkcombo, left))
2193 {
2194 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2195 }
2196 }
2197
2198 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2199 {
2200 if(misaligned(currmap, scr, checkcombo, right))
2201 {
2202 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2203 }
2204 }
2205
2206 int32_t tempalign;
2207
2208 //check top left corner
2209 checkcombo=0;
2210 tempalign=0;
2211 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2212 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2213
2214 switch(tempalign)
2215 {
2216 case 0:
2217 break;
2218
2219 case 1: //up
2220 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2221 break;
2222
2223 case 2: //left
2224 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2225 break;
2226
2227 case 3: //up-left
2228 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2229 break;
2230 }
2231
2232 //check top right corner
2233 checkcombo=15;
2234 tempalign=0;
2235 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2236 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2237
2238 switch(tempalign)
2239 {
2240 case 0:
2241 break;
2242
2243 case 1: //up
2244 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 break;
2246
2247 case 2: //right
2248 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2249 break;
2250
2251 case 3: //up-right
2252 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 break;
2254 }
2255
2256 //check bottom left corner
2257 checkcombo=160;
2258 tempalign=0;
2259 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2260 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2261
2262 switch(tempalign)
2263 {
2264 case 0:
2265 break;
2266
2267 case 1: //down
2268 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2269 break;
2270
2271 case 2: //left
2272 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2273 break;
2274
2275 case 3: //down-left
2276 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2277 break;
2278 }
2279
2280 //check bottom right corner
2281
2282 checkcombo=175;
2283 tempalign=0;
2284 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2285 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2286
2287 switch(tempalign)
2288 {
2289 case 0:
2290 break;
2291
2292 case 1: //down
2293 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2294 break;
2295
2296 case 2: //right
2297 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2298 break;
2299
2300 case 3: //down-right
2301 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2302 break;
2303 }
2304 }
2305 }
2306 }
2307
2308 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2309 {
2310 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2311 }
2312
2313 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2314 {
2315 if (map < 0 || screen < 0) return 0;
2316
2317 if(pos>175 || pos < 0)
2318 return 0;
2319
2320 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2321
2322 if(m->valid==0) return 0;
2323
2324 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2325
2326 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2327
2328 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2329
2330 if(scr->valid==0) return 0;
2331
2332 return scr->data[pos]; // entire combo code
2333 }
2334
2335 // Takes array index layer num., not actual layer num.
2336 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2337 {
2338 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2339
2340 if(map<0)
2341 map=currmap;
2342
2343 if(scr<0)
2344 scr=currscr;
2345
2346 mapscr *screen1;
2347
2348 if(prv_mode)
2349 {
2350 screen1=get_prvscr();
2351 }
2352 else
2353 {
2354 screen1=AbsoluteScr(currmap,currscr);
2355 }
2356
2357 int32_t layermap;
2358 layermap=screen1->layermap[lyr]-1;
2359
2360 if(layermap<0 || layermap >= map_count) return 0;
2361
2362 mapscr *layer;
2363
2364 if(prv_mode)
2365 layer = &prvlayers[lyr];
2366 else
2367 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2368
2369 int32_t combo = COMBOPOS(x,y);
2370
2371 if(combo>175 || combo < 0)
2372 return 0;
2373
2374 return layer->data[combo];
2375 }
2376
2377 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2378 {
2379 if(map<0)
2380 map=currmap;
2381
2382 if(scr<0)
2383 scr=currscr;
2384
2385 mapscr *screen1;
2386
2387 if(prv_mode)
2388 {
2389 screen1=get_prvscr();
2390 }
2391 else
2392 {
2393 screen1=AbsoluteScr(currmap,currscr);
2394 }
2395
2396 x = vbound(x, 0, 16*16);
2397 y = vbound(y, 0, 11*16);
2398 int32_t combo = COMBOPOS(x,y);
2399
2400 if(combo>175 || combo < 0)
2401 return 0;
2402
2403 return screen1->data[combo];
2404 }
2405
2406 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2407 {
2408 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2409 }
2410
2411 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2412 {
2413 if (map < 0 || screen < 0) return 0;
2414
2415 if(pos>175 || pos < 0)
2416 return 0;
2417
2418 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2419
2420 if(m->valid==0) return 0;
2421
2422 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2423
2424 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2425
2426 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2427
2428 if(scr->valid==0) return 0;
2429
2430 return scr->sflag[pos]; // entire combo code
2431 }
2432
2433 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2434 {
2435 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2436
2437 if(map<0)
2438 map=currmap;
2439
2440 if(scr<0)
2441 scr=currscr;
2442
2443 mapscr *screen1;
2444
2445 if(prv_mode)
2446 {
2447 screen1=get_prvscr();
2448 }
2449 else
2450 {
2451 screen1=AbsoluteScr(currmap,currscr);
2452 }
2453
2454 int32_t layermap;
2455 layermap=screen1->layermap[lyr]-1;
2456
2457 if(layermap<0 || layermap >= map_count) return 0;
2458
2459 mapscr *layer;
2460
2461 if(prv_mode)
2462 layer = &prvlayers[lyr];
2463 else
2464 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2465
2466 int32_t combo = COMBOPOS(x,y);
2467
2468 if(combo>175 || combo < 0)
2469 return 0;
2470
2471 return layer->sflag[combo];
2472 }
2473
2474 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2475 {
2476 if(map<0)
2477 map=currmap;
2478
2479 if(scr<0)
2480 scr=currscr;
2481
2482 mapscr *screen1;
2483
2484 if(prv_mode)
2485 {
2486 screen1=get_prvscr();
2487 }
2488 else
2489 {
2490 screen1=AbsoluteScr(currmap,currscr);
2491 }
2492
2493 x = vbound(x, 0, 16*16);
2494 y = vbound(y, 0, 11*16);
2495 int32_t combo = COMBOPOS(x,y);
2496
2497 if(combo>175 || combo < 0)
2498 return 0;
2499
2500 return screen1->sflag[combo];
2501 }
2502
2503 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2504 {
2505 mapscr *layers[7];
2506 mapscr *basescr;
2507 if(prv_mode)
2508 {
2509 layers[0] = &prvscr;
2510 basescr = layers[0];
2511 for(auto q = 1; q < 7; ++q)
2512 {
2513 if(prvlayers[q-1].valid)
2514 layers[q] = &(prvlayers[q-1]);
2515 else layers[q] = NULL;
2516 }
2517 }
2518 else
2519 {
2520 layers[0] = AbsoluteScr(currmap, currscr);
2521 basescr = layers[0];
2522 for(auto q = 1; q < 7; ++q)
2523 {
2524 int32_t lmap = basescr->layermap[q-1]-1;
2525 int32_t lscr = basescr->layerscreen[q-1];
2526 if(lmap < 0)
2527 layers[q] = NULL;
2528 else layers[q] = AbsoluteScr(lmap, lscr);
2529 }
2530 }
2531 for(auto q = 0; q < 7; ++q)
2532 {
2533 if(!layers[q]) continue;
2534 for(auto pos = 0; pos < 176; ++pos)
2535 {
2536 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2537 if(cmb.type == cTORCH)
2538 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2539 }
2540 }
2541 word maxffc = basescr->numFFC();
2542 for(auto q = 0; q < maxffc; ++q)
2543 {
2544 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2545 if(cmb.type == cTORCH)
2546 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2547 }
2548 }
2549
2550 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2551 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2552 {
2553 newcombo const& cmb = combobuf[cid];
2554 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2555 if(dither)
2556 {
2557 if (LayerDitherSz == 0)
2558 return;
2559 BITMAP* buf = create_bitmap_ex(8,16,16);
2560 clear_bitmap(buf);
2561 overcombo(buf,0,0,cid,cset);
2562 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2563 if(over)
2564 {
2565 if(transp)
2566 {
2567 color_map = &trans_table2;
2568 draw_trans_sprite(dest, buf, x, y);
2569 color_map = &trans_table;
2570 }
2571 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2572 }
2573 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2574 destroy_bitmap(buf);
2575 }
2576 else if(over)
2577 {
2578 if(transp)
2579 overcombotranslucent(dest,x,y,cid,cset,0);
2580 else overcombo(dest,x,y,cid,cset);
2581 }
2582 else put_combo(dest,x,y,cid,cset,flags,sflag);
2583 }
2584 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2585 {
2586 if(!md) return;
2587 for (int32_t i = 0; i < 176; i++)
2588 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2589 }
2590 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2591 {
2592 if(!md) return;
2593 for (int32_t i = 0; i < 176; i++)
2594 {
2595 int data = md->data[i];
2596 if(combo_class_buf[combobuf[data].type].overhead)
2597 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2598 }
2599 }
2600 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2601 {
2602 if(!LayerMaskInt[lyr])
2603 return nullptr;
2604 if(lyr == 0)
2605 return basescr;
2606 int layermap = basescr->layermap[lyr-1]-1;
2607
2608 if(layermap>-1 && layermap<map_count)
2609 {
2610 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2611 return &TheMaps[layerscreen];
2612 }
2613 return nullptr;
2614 }
2615 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2616 {
2617 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2618 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2619
2620 if(map<0)
2621 map=currmap;
2622
2623 if(scr<0)
2624 scr=currscr;
2625
2626 mapscr *basescr;
2627 mapscr* layers[7] = {nullptr};
2628
2629 if(prv_mode)
2630 {
2631 hl_layer = -1;
2632 basescr=get_prvscr();
2633 }
2634 else
2635 {
2636 basescr=AbsoluteScr(map,scr);
2637 }
2638 layers[0] = _zmap_get_lyr_checked(0,basescr);
2639 for(int lyr = 1; lyr < 7; ++lyr)
2640 {
2641 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2642 : _zmap_get_lyr_checked(lyr,basescr);
2643 }
2644
2645 int32_t layermap, layerscreen;
2646 if(CurrentLayer < 1)
2647 layermap = -1;
2648 else
2649 {
2650 layermap=basescr->layermap[CurrentLayer-1]-1;
2651
2652 if(layermap<0)
2653 CurrentLayer=0;
2654 }
2655
2656 if(!(basescr->valid&mVALID))
2657 {
2658 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2659 rectfill(dest,x,y,x+255,y+175,vc(1));
2660
2661 if(ShowMisalignments)
2662 {
2663 check_alignments(dest,x,y,scr);
2664 }
2665
2666 return;
2667 }
2668
2669 if(LayerMaskInt[0]==0)
2670 {
2671 byte bgfill = 0;
2672 if (LayerDitherBG > -1)
2673 bgfill = vc(LayerDitherBG);
2674 rectfill(dest,x,y,x+255,y+175,bgfill);
2675 }
2676
2677 resize_mouse_pos=true;
2678 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2679 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2680
2681 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2682 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2683
2684 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2685
2686 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2687
2688 for(int32_t i=MAXFFCS-1; i>=0; i--)
2689 {
2690 if(basescr->ffcs[i].data)
2691 {
2692 if(!(basescr->ffcs[i].flags&ffCHANGER))
2693 {
2694 if(!(basescr->ffcs[i].flags&ffOVERLAY))
2695 {
2696 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2697 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2698
2699 if(basescr->ffcs[i].flags&ffTRANS)
2700 {
2701 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2702 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2703 }
2704 else
2705 {
2706 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2707 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2708 }
2709 }
2710 }
2711 }
2712 }
2713
2714 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2715 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2716
2717 int32_t doortype[4];
2718
2719 for(int32_t i=0; i<4; i++)
2720 {
2721 switch(basescr->door[i])
2722 {
2723 case dOPEN:
2724 doortype[i]=dt_pass;
2725 break;
2726
2727 case dLOCKED:
2728 doortype[i]=dt_lock;
2729 break;
2730
2731 case d1WAYSHUTTER:
2732 case dSHUTTER:
2733 doortype[i]=dt_shut;
2734 break;
2735
2736 case dBOSS:
2737 doortype[i]=dt_boss;
2738 break;
2739
2740 case dBOMB:
2741 doortype[i]=dt_bomb;
2742 break;
2743 }
2744 }
2745
2746 switch(basescr->door[up])
2747 {
2748 case dBOMB:
2749 over_door(dest,39,up,x,y,false, scr);
2750 [[fallthrough]];
2751 case dOPEN:
2752 case dLOCKED:
2753 case d1WAYSHUTTER:
2754 case dSHUTTER:
2755 case dBOSS:
2756 put_door(dest,7,up,doortype[up],x,y,false,scr);
2757 break;
2758
2759 case dWALK:
2760 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2761 {
2762 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2763 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2764 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2765 }
2766 else
2767
2768 {
2769 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2770 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2771 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2772 }
2773
2774 break;
2775 }
2776
2777 switch(basescr->door[down])
2778 {
2779 case dBOMB:
2780 over_door(dest,135,down,x,y,false,scr);
2781 [[fallthrough]];
2782 case dOPEN:
2783 case dLOCKED:
2784 case d1WAYSHUTTER:
2785 case dSHUTTER:
2786 case dBOSS:
2787 put_door(dest,151,down,doortype[down],x,y,false,scr);
2788 break;
2789
2790 case dWALK:
2791 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2792 {
2793 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2794 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2795 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2796 }
2797 else
2798 {
2799 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2800 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2801 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2802 }
2803
2804 break;
2805 }
2806
2807 switch(basescr->door[left])
2808 {
2809 case dBOMB:
2810 over_door(dest,66,left,x,y,false,scr);
2811 [[fallthrough]];
2812 case dOPEN:
2813 case dLOCKED:
2814 case d1WAYSHUTTER:
2815 case dSHUTTER:
2816 case dBOSS:
2817 put_door(dest,64,left,doortype[left],x,y,false,scr);
2818 break;
2819
2820 case dWALK:
2821 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2822 {
2823 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2824 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2825 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2826 }
2827 else
2828 {
2829 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2830 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2831 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2832 }
2833
2834 break;
2835 }
2836
2837 switch(basescr->door[right])
2838 {
2839
2840 case dBOMB:
2841 over_door(dest,77,right,x,y,false,scr);
2842 [[fallthrough]];
2843 case dOPEN:
2844 case dLOCKED:
2845 case d1WAYSHUTTER:
2846 case dSHUTTER:
2847 case dBOSS:
2848 put_door(dest,78,right,doortype[right],x,y,false,scr);
2849 break;
2850
2851 case dWALK:
2852 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2853 {
2854 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2855 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2856 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2857 }
2858 else
2859 {
2860 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2861 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2862 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2863 }
2864
2865 break;
2866 }
2867
2868 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2869 {
2870 frame=0;
2871 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2872 }
2873
2874 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2875 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2876 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2877
2878 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2879
2880 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2881 {
2882 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2883 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2884 }
2885 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2886
2887 for(int32_t i=MAXFFCS-1; i>=0; i--)
2888 {
2889 if(basescr->ffcs[i].data)
2890 {
2891 if(!(basescr->ffcs[i].flags&ffCHANGER))
2892 {
2893 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2894 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2895
2896 if(basescr->ffcs[i].flags&ffOVERLAY)
2897 {
2898 if(basescr->ffcs[i].flags&ffTRANS)
2899 {
2900 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2901 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2902 }
2903 else
2904 {
2905 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2906 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2907 }
2908 }
2909 }
2910 }
2911 }
2912
2913 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2914
2915 for(int32_t i=MAXFFCS-1; i>=0; i--)
2916 if(basescr->ffcs[i].data)
2917 if(basescr->ffcs[i].flags&ffCHANGER)
2918 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2919
2920 if(flags&cWALK)
2921 {
2922 if(layers[0])
2923 for(int32_t i=0; i<176; i++)
2924 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2925
2926 for(int32_t k=0; k<2; k++)
2927 {
2928 if(layers[k+1])
2929 for(int32_t i=0; i<176; i++)
2930 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2931 }
2932 for(int32_t i=MAXFFCS-1; i>=0; i--)
2933 {
2934 if(auto data = basescr->ffcs[i].data)
2935 {
2936 if(!(basescr->ffcs[i].flags&ffCHANGER))
2937 {
2938 newcombo const& cmb = combobuf[data];
2939 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2940 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2941
2942 if(basescr->ffcs[i].flags&ffSOLID)
2943 {
2944 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2945 }
2946
2947 if(cmb.type == cSLOPE)
2948 {
2949 slope_info s(cmb, tx, ty);
2950 s.draw(dest, 0, 0, COLOR_SLOPE);
2951 }
2952 }
2953 }
2954 }
2955 }
2956
2957 if(flags&cFLAGS)
2958 {
2959 if(LayerMaskInt[CurrentLayer]!=0)
2960 {
2961 for(int32_t i=0; i<176; i++)
2962 {
2963 if(CurrentLayer==0)
2964 {
2965 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2966 }
2967 else
2968 {
2969 if(prv_mode)
2970 {
2971 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2972 }
2973 else
2974 {
2975 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2976
2977 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2978 {
2979 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2980 TheMaps[_lscr].data[i],
2981 TheMaps[_lscr].cset[i], flags,
2982 TheMaps[_lscr].sflag[i]);
2983 }
2984 }
2985 }
2986 }
2987 }
2988 }
2989
2990 int32_t dark = basescr->flags&cDARK;
2991
2992 if(dark && !(flags&cNODARK)
2993 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2994 {
2995 for(int32_t j=0; j<80; j++)
2996 {
2997 for(int32_t i=0; i<(80)-j; i++)
2998 {
2999 if(((i^j)&1)==0)
3000 {
3001 putpixel(dest,x+i,y+j,vc(blackout_color));
3002 }
3003 }
3004 }
3005 }
3006
3007 if(ShowMisalignments)
3008 {
3009 check_alignments(dest,x,y,scr);
3010 }
3011
3012 resize_mouse_pos=false;
3013 }
3014
3015 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3016 {
3017 if(map<0)
3018 map=currmap;
3019
3020 if(scr<0)
3021 scr=currscr;
3022
3023 mapscr* layer=AbsoluteScr(map,scr);
3024 int32_t layermap=0, layerscreen=0;
3025
3026 if(!(layer->valid&mVALID))
3027 {
3028 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3029 rectfill(dest,x,y,x+255,y+15,vc(1));
3030 return;
3031 }
3032
3033 int32_t dark = layer->flags&4;
3034
3035 resize_mouse_pos=true;
3036
3037 if(LayerMaskInt[0]==0)
3038 {
3039 rectfill(dest,x,y,x+255,y+15,0);
3040 }
3041
3042 // int32_t cs=2;
3043
3044 for(int32_t k=1; k<3; k++)
3045 {
3046 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3047 {
3048 layermap=layer->layermap[k]-1;
3049
3050 if(layermap>-1 && layermap<map_count)
3051 {
3052 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3053
3054 for(int32_t i=c; i<(c&0xF0)+16; i++)
3055 {
3056 auto data = TheMaps[layerscreen].data[i];
3057 auto cs = TheMaps[layerscreen].cset[i];
3058 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3059 }
3060 }
3061 }
3062 }
3063
3064 if(LayerMaskInt[0]!=0)
3065 {
3066 for(int32_t i=c; i<(c&0xF0)+16; i++)
3067 {
3068 word cmbdat = (i < 176 ? layer->data[i] : 0);
3069 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3070 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3071 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3072 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3073 }
3074 }
3075
3076 for(int32_t k=0; k<2; k++)
3077 {
3078 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3079 {
3080 layermap=layer->layermap[k]-1;
3081
3082 if(layermap>-1 && layermap<map_count)
3083 {
3084 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3085
3086 for(int32_t i=c; i<(c&0xF0)+16; i++)
3087 {
3088 auto data = TheMaps[layerscreen].data[i];
3089 auto cs = TheMaps[layerscreen].cset[i];
3090 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3091 }
3092 }
3093 }
3094 }
3095
3096 int32_t doortype[4];
3097
3098 for(int32_t i=0; i<4; i++)
3099 {
3100 switch(layer->door[i])
3101 {
3102 case dOPEN:
3103 doortype[i]=dt_pass;
3104 break;
3105
3106 case dLOCKED:
3107 doortype[i]=dt_lock;
3108 break;
3109
3110 case d1WAYSHUTTER:
3111 case dSHUTTER:
3112 doortype[i]=dt_shut;
3113 break;
3114
3115 case dBOSS:
3116 doortype[i]=dt_boss;
3117 break;
3118
3119 case dBOMB:
3120 doortype[i]=dt_bomb;
3121 break;
3122 }
3123 }
3124
3125 if(c<16)
3126 {
3127 switch(layer->door[up])
3128 {
3129 case dBOMB:
3130 case dOPEN:
3131 case dLOCKED:
3132 case d1WAYSHUTTER:
3133 case dSHUTTER:
3134 case dBOSS:
3135 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3136 break;
3137 }
3138 }
3139 else if(c>159)
3140 {
3141 switch(layer->door[down])
3142 {
3143 case dBOMB:
3144 case dOPEN:
3145 case dLOCKED:
3146 case d1WAYSHUTTER:
3147 case dSHUTTER:
3148 case dBOSS:
3149 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3150 break;
3151 }
3152 }
3153
3154 for(int32_t k=2; k<4; k++)
3155 {
3156 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3157 {
3158 layermap=layer->layermap[k]-1;
3159
3160 if(layermap>-1 && layermap<map_count)
3161 {
3162 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3163
3164 for(int32_t i=c; i<(c&0xF0)+16; i++)
3165 {
3166 if(layer->layeropacity[k]<255)
3167 {
3168 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3169 }
3170 else
3171 {
3172 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3173 }
3174 }
3175 }
3176 }
3177 }
3178
3179 //Overhead L0
3180 if(LayerMaskInt[0]!=0)
3181 {
3182 for(int32_t i=c; i<(c&0xF0)+16; i++)
3183 {
3184 int32_t ct1=layer->data[i];
3185 int32_t ct3=combobuf[ct1].type;
3186
3187 if(combo_class_buf[ct3].overhead)
3188 {
3189 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3190 }
3191 }
3192 }
3193
3194 //Overhead L1/2
3195 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3196 {
3197 for(int32_t k = 0; k < 2; ++k)
3198 {
3199 if(LayerMaskInt[k+1]!=0)
3200 {
3201 layermap=layer->layermap[k]-1;
3202
3203 if(layermap>-1 && layermap<map_count)
3204 {
3205 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3206 for(int32_t i=c; i<(c&0xF0)+16; i++)
3207 {
3208 auto data = TheMaps[layerscreen].data[i];
3209 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3210 auto cs = TheMaps[layerscreen].cset[i];
3211 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3212 }
3213 }
3214 }
3215 }
3216 }
3217
3218 for(int32_t k=4; k<6; k++)
3219 {
3220 if(LayerMaskInt[k+1]!=0)
3221 {
3222 layermap=layer->layermap[k]-1;
3223
3224 if(layermap>-1 && layermap<map_count)
3225 {
3226 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3227
3228 for(int32_t i=c; i<(c&0xF0)+16; i++)
3229 {
3230 auto data = TheMaps[layerscreen].data[i];
3231 auto cs = TheMaps[layerscreen].cset[i];
3232 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3233 }
3234 }
3235 }
3236 }
3237
3238 if(flags&cWALK)
3239 {
3240 if(LayerMaskInt[0]!=0)
3241 {
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3245 }
3246 }
3247
3248 for(int32_t k=0; k<2; k++)
3249 {
3250 if(LayerMaskInt[k+1]!=0)
3251 {
3252 for(int32_t i=c; i<(c&0xF0)+16; i++)
3253 {
3254 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3255 }
3256 }
3257 }
3258 }
3259
3260 if(flags&cFLAGS)
3261 {
3262 if(LayerMaskInt[CurrentLayer]!=0)
3263 {
3264 for(int32_t i=c; i<(c&0xF0)+16; i++)
3265 {
3266 if(CurrentLayer==0)
3267 {
3268 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3269 }
3270 else
3271 {
3272 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3273
3274 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3275 {
3276 if(i < 176)
3277 {
3278 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3279 TheMaps[_lscr].data[i],
3280 TheMaps[_lscr].cset[i], flags|dark,
3281 TheMaps[_lscr].sflag[i]);
3282 }
3283 else
3284 {
3285 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3286 }
3287 }
3288 }
3289 }
3290 }
3291
3292 /*
3293 if (LayerMaskInt[0]!=0) {
3294 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3295 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3296 }
3297 }
3298 */
3299 }
3300
3301 if(ShowMisalignments)
3302 {
3303 if(c<16)
3304 {
3305 check_alignments(dest,x,y,scr);
3306 }
3307 else if(c>159)
3308 {
3309 check_alignments(dest,x,y-160,scr);
3310 }
3311 }
3312
3313 resize_mouse_pos=false;
3314
3315 }
3316
3317 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3318 {
3319 if(map<0)
3320 map=currmap;
3321
3322 if(scr<0)
3323 scr=currscr;
3324
3325 mapscr* layer=AbsoluteScr(map,scr);
3326 int32_t layermap=0, layerscreen=0;
3327
3328 if(!(layer->valid&mVALID))
3329 {
3330 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3331 rectfill(dest,x,y,x+15,y+175,vc(1));
3332 return;
3333 }
3334
3335 int32_t dark = layer->flags&4;
3336
3337 resize_mouse_pos=true;
3338
3339
3340 if(LayerMaskInt[0]==0)
3341 {
3342 rectfill(dest,x,y,x+15,y+175,0);
3343 }
3344
3345 // int32_t cs=2;
3346
3347 for(int32_t k=1; k<3; k++)
3348 {
3349 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3350 {
3351 layermap=layer->layermap[k]-1;
3352
3353 if(layermap>-1 && layermap<map_count)
3354 {
3355 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3356
3357 for(int32_t i=c; i<176; i+=16)
3358 {
3359 auto data = TheMaps[layerscreen].data[i];
3360 auto cs = TheMaps[layerscreen].cset[i];
3361 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3362 }
3363 }
3364 }
3365 }
3366
3367 if(LayerMaskInt[0]!=0)
3368 {
3369 for(int32_t i=c; i<176; i+=16)
3370 {
3371 word cmbdat = layer->data[i];
3372 byte cmbcset = layer->cset[i];
3373 int32_t cmbflag = layer->sflag[i];
3374 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3375 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3376 }
3377 }
3378
3379 for(int32_t k=0; k<2; k++)
3380 {
3381 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3382 {
3383 layermap=layer->layermap[k]-1;
3384
3385 if(layermap>-1 && layermap<map_count)
3386 {
3387 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3388
3389 for(int32_t i=c; i<176; i+=16)
3390 {
3391 auto data = TheMaps[layerscreen].data[i];
3392 auto cs = TheMaps[layerscreen].cset[i];
3393 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3394 }
3395 }
3396 }
3397 }
3398
3399 int32_t doortype[4];
3400
3401 for(int32_t i=0; i<4; i++)
3402 {
3403 switch(layer->door[i])
3404 {
3405 case dOPEN:
3406 doortype[i]=dt_pass;
3407 break;
3408
3409 case dLOCKED:
3410 doortype[i]=dt_lock;
3411 break;
3412
3413 case d1WAYSHUTTER:
3414 case dSHUTTER:
3415 doortype[i]=dt_shut;
3416 break;
3417
3418 case dBOSS:
3419 doortype[i]=dt_boss;
3420 break;
3421
3422 case dBOMB:
3423 doortype[i]=dt_bomb;
3424 break;
3425 }
3426 }
3427
3428 if((c&0x0F)==0)
3429 {
3430 switch(layer->door[left])
3431 {
3432
3433 case dBOMB:
3434 case dOPEN:
3435 case dLOCKED:
3436 case d1WAYSHUTTER:
3437 case dSHUTTER:
3438 case dBOSS:
3439 // put_door(dest,64,left,doortype[left],x+256,y,true);
3440 put_door(dest,64,left,doortype[left],x,y,true,scr);
3441 break;
3442 }
3443 }
3444 else if((c&0x0F)==15)
3445 {
3446 switch(layer->door[right])
3447 {
3448 case dBOMB:
3449 case dOPEN:
3450 case dLOCKED:
3451 case d1WAYSHUTTER:
3452 case dSHUTTER:
3453 case dBOSS:
3454 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3455 break;
3456 }
3457 }
3458
3459 for(int32_t k=2; k<4; k++)
3460 {
3461 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3462 {
3463 layermap=layer->layermap[k]-1;
3464
3465 if(layermap>-1 && layermap<map_count)
3466 {
3467 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3468
3469 for(int32_t i=c; i<176; i+=16)
3470 {
3471 auto data = TheMaps[layerscreen].data[i];
3472 auto cs = TheMaps[layerscreen].cset[i];
3473 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3474 }
3475 }
3476 }
3477 }
3478
3479 //Overhead L0
3480 if(LayerMaskInt[0]!=0)
3481 {
3482 for(int32_t i=c; i<176; i+=16)
3483 {
3484 auto data = TheMaps[layerscreen].data[i];
3485 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3486 auto cs = TheMaps[layerscreen].cset[i];
3487 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3488 }
3489 }
3490 //Overhead L1/2
3491 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3492 {
3493 for(int32_t k = 0; k < 2; ++k)
3494 {
3495 if(LayerMaskInt[k+1]!=0)
3496 {
3497 layermap=layer->layermap[k]-1;
3498
3499 if(layermap>-1 && layermap<map_count)
3500 {
3501 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3502 for(int32_t i=c; i<176; i+=16)
3503 {
3504 auto data = TheMaps[layerscreen].data[i];
3505 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3506 auto cs = TheMaps[layerscreen].cset[i];
3507 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3508 }
3509 }
3510 }
3511 }
3512 }
3513
3514
3515 for(int32_t k=4; k<6; k++)
3516 {
3517 if(LayerMaskInt[k+1]!=0)
3518 {
3519 layermap=layer->layermap[k]-1;
3520
3521 if(layermap>-1 && layermap<map_count)
3522 {
3523 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3524
3525 for(int32_t i=c; i<176; i+=16)
3526 {
3527 auto data = TheMaps[layerscreen].data[i];
3528 auto cs = TheMaps[layerscreen].cset[i];
3529 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3530 }
3531 }
3532 }
3533 }
3534
3535 if(flags&cWALK)
3536 {
3537 if(LayerMaskInt[0]!=0)
3538 {
3539 for(int32_t i=c&0xF; i<176; i+=16)
3540 {
3541 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3542 }
3543 }
3544
3545 for(int32_t k=0; k<2; k++)
3546 {
3547 if(LayerMaskInt[k+1]!=0)
3548 {
3549 for(int32_t i=c&0xF; i<176; i+=16)
3550 {
3551 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3552 }
3553 }
3554 }
3555 }
3556
3557 if(flags&cFLAGS)
3558 {
3559 if(LayerMaskInt[CurrentLayer]!=0)
3560 {
3561 for(int32_t i=c; i<176; i+=16)
3562 {
3563 if(CurrentLayer==0)
3564 {
3565 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3566 }
3567 else
3568 {
3569 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3570
3571 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3572 {
3573 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3574 TheMaps[_lscr].data[i],
3575 TheMaps[_lscr].cset[i], flags|dark,
3576 TheMaps[_lscr].sflag[i]);
3577 }
3578 }
3579 }
3580 }
3581 }
3582
3583 if(ShowMisalignments)
3584 {
3585 if((c&0x0F)==0)
3586 {
3587 check_alignments(dest,x,y,scr);
3588 }
3589 else if((c&0x0F)==15)
3590 {
3591 check_alignments(dest,x-240,y,scr);
3592 }
3593 }
3594
3595 resize_mouse_pos=false;
3596 }
3597
3598 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3599 {
3600 if(map<0)
3601 map=currmap;
3602
3603 if(scr<0)
3604 scr=currscr;
3605
3606 mapscr* layer=AbsoluteScr(map,scr);
3607 int32_t layermap=0, layerscreen=0;
3608
3609 if(!(layer->valid&mVALID))
3610 {
3611 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3612 rectfill(dest,x,y,x+15,y+15,vc(1));
3613 return;
3614 }
3615
3616 int32_t dark = layer->flags&4;
3617
3618 resize_mouse_pos=true;
3619
3620 if(LayerMaskInt[0]!=0)
3621 {
3622 rectfill(dest,x,y,x+15,y+15,0);
3623 }
3624
3625 for(int32_t k=1; k<3; k++)
3626 {
3627 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3628 {
3629 layermap=layer->layermap[k]-1;
3630
3631 if(layermap>-1 && layermap<map_count)
3632 {
3633 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3634
3635 auto data = TheMaps[layerscreen].data[c];
3636 auto cs = TheMaps[layerscreen].cset[c];
3637 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3638 }
3639 }
3640 }
3641
3642 // int32_t cs=2;
3643 if(LayerMaskInt[0]!=0)
3644 {
3645 word cmbdat = layer->data[c];
3646 byte cmbcset = layer->cset[c];
3647 int32_t cmbflag = layer->sflag[c];
3648 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3649 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3650 }
3651
3652
3653 for(int32_t k=0; k<2; k++)
3654 {
3655 if(LayerMaskInt[k+1]!=0)
3656 {
3657 layermap=layer->layermap[k]-1;
3658
3659 if(layermap>-1 && layermap<map_count)
3660 {
3661 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3662
3663 auto data = TheMaps[layerscreen].data[c];
3664 auto cs = TheMaps[layerscreen].cset[c];
3665 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3666 }
3667 }
3668 }
3669
3670 for(int32_t k=2; k<4; k++)
3671 {
3672 if(LayerMaskInt[k+1]!=0)
3673 {
3674 layermap=layer->layermap[k]-1;
3675
3676 if(layermap>-1 && layermap<map_count)
3677 {
3678 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3679 auto data = TheMaps[layerscreen].data[c];
3680 auto cs = TheMaps[layerscreen].cset[c];
3681 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3682 }
3683 }
3684 }
3685
3686 //Overhead L0
3687 if(LayerMaskInt[0]!=0)
3688 {
3689 auto data = TheMaps[layerscreen].data[c];
3690 if(combo_class_buf[combobuf[data].type].overhead)
3691 {
3692 auto cs = TheMaps[layerscreen].cset[c];
3693 drawcombo(dest,x,y,data,cs,0,0);
3694 }
3695 }
3696 //Overhead L1/2
3697 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3698 {
3699 for(int32_t k = 0; k < 2; ++k)
3700 {
3701 if(LayerMaskInt[k+1]!=0)
3702 {
3703 layermap=layer->layermap[k]-1;
3704
3705 if(layermap>-1 && layermap<map_count)
3706 {
3707 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3708 auto data = TheMaps[layerscreen].data[c];
3709 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3710 auto cs = TheMaps[layerscreen].cset[c];
3711 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3712 }
3713 }
3714 }
3715 }
3716
3717
3718 for(int32_t k=4; k<6; k++)
3719 {
3720 if(LayerMaskInt[k+1]!=0)
3721 {
3722 layermap=layer->layermap[k]-1;
3723
3724 if(layermap>-1 && layermap<map_count)
3725 {
3726 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3727 auto data = TheMaps[layerscreen].data[c];
3728 auto cs = TheMaps[layerscreen].cset[c];
3729 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3730 }
3731 }
3732 }
3733
3734 if(flags&cWALK)
3735 {
3736 if(LayerMaskInt[0]!=0)
3737 {
3738 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3739 }
3740
3741 for(int32_t k=0; k<2; k++)
3742 {
3743 if(LayerMaskInt[k+1]!=0)
3744 {
3745 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3746 }
3747 }
3748 }
3749
3750 if(flags&cFLAGS)
3751 {
3752 if(LayerMaskInt[CurrentLayer]!=0)
3753 {
3754 int32_t i = c;
3755 //for(int32_t i=c; i==c; i++)
3756 {
3757 if(CurrentLayer==0)
3758 {
3759 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3760 }
3761 else
3762 {
3763 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3764
3765 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3766 {
3767 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3768 TheMaps[_lscr].data[i],
3769 TheMaps[_lscr].cset[i], flags|dark,
3770 TheMaps[_lscr].sflag[i]);
3771 }
3772 }
3773 }
3774 }
3775 }
3776
3777 if(ShowMisalignments)
3778 {
3779 switch(c)
3780 {
3781 case 0:
3782 check_alignments(dest,x,y,scr);
3783 break;
3784
3785 case 15:
3786 check_alignments(dest,x-240,y,scr);
3787 break;
3788
3789 case 160:
3790 check_alignments(dest,x,y-160,scr);
3791 break;
3792
3793 case 175:
3794 check_alignments(dest,x-240,y-160,scr);
3795 break;
3796 }
3797 }
3798
3799 resize_mouse_pos=false;
3800
3801 }
3802
3803 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3804 {
3805 if (InvalidBG == 2)
3806 {
3807 draw_checkerboard(dest, x, y, 16);
3808 }
3809 else if(InvalidBG == 1)
3810 {
3811 for(int32_t dy=0; dy<16; dy++)
3812 {
3813 for(int32_t dx=0; dx<16; dx++)
3814 {
3815 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3816 }
3817 }
3818 }
3819 else
3820 {
3821 rectfill(dest, x, y, x+15, y+15, vc(0));
3822 rect(dest, x, y, x+15, y+15, vc(15));
3823 line(dest, x, y, x+15, y+15, vc(15));
3824 line(dest, x, y+15, x+15, y, vc(15));
3825 }
3826 }
3827
3828 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3829 {
3830 if (InvalidBG == 2)
3831 {
3832 for(int32_t q = 0; q < 11; ++q)
3833 draw_checkerboard(dest, x, y + q * 16, 16);
3834 }
3835 else if(InvalidBG == 1)
3836 {
3837 for(int32_t dy=0; dy<176; dy++)
3838 {
3839 for(int32_t dx=0; dx<16; dx++)
3840 {
3841 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3842 }
3843 }
3844 }
3845 else
3846 {
3847 rectfill(dest, x, y, x+15, y+175, vc(0));
3848 rect(dest, x, y, x+15, y+175, vc(15));
3849 line(dest, x, y, x+15, y+175, vc(15));
3850 line(dest, x, y+175, x+15, y, vc(15));
3851 }
3852 }
3853
3854 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3855 {
3856 if (InvalidBG == 2)
3857 {
3858 for (int32_t q = 0; q < 16; ++q)
3859 draw_checkerboard(dest, x + q * 16, y, 16);
3860 }
3861 else if(InvalidBG == 1)
3862 {
3863 for(int32_t dy=0; dy<16; dy++)
3864 {
3865 for(int32_t dx=0; dx<256; dx++)
3866 {
3867 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3868 }
3869 }
3870 }
3871 else
3872 {
3873 rectfill(dest, x, y, x+255, y+15, vc(0));
3874 rect(dest, x, y, x+255, y+15, vc(15));
3875 line(dest, x, y, x+255, y+15, vc(15));
3876 line(dest, x, y+15, x+255, y, vc(15));
3877 }
3878 }
3879
3880 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3881 {
3882 for(int32_t i=0; i<176; i++)
3883 {
3884 word cmbdat = screens[TEMPLATE].data[i];
3885 byte cmbcset = screens[TEMPLATE].cset[i];
3886 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3887 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3888 }
3889 }
3890
3891 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3892 {
3893 for(int32_t i=0; i<176; i++)
3894 {
3895 word cmbdat = screens[TEMPLATE2].data[i];
3896 byte cmbcset = screens[TEMPLATE2].cset[i];
3897 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3898 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3899 }
3900 }
3901
3902 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3903 {
3904 word cmbdat = screens[TEMPLATE].data[pos];
3905 byte cmbcset = screens[TEMPLATE].cset[pos];
3906 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3907 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3908 }
3909
3910 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3911 {
3912 word cmbdat = screens[currscr].secretcombo[scombo];
3913 byte cmbcset = screens[currscr].secretcset[scombo];
3914 byte cmbflag = screens[currscr].secretflag[scombo];
3915 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3916 }
3917
3918 void zmap::scroll(int32_t dir, bool warp)
3919 {
3920 if(currmap<map_count)
3921 {
3922 switch(dir)
3923 {
3924 case up:
3925 if(warp && Map.CurrScr()->flags2&wfUP)
3926 {
3927 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3928 }
3929 else if(currscr>15)
3930 {
3931 setCurrScr(currscr-16);
3932 }
3933
3934 break;
3935
3936 case down:
3937 if(warp && Map.CurrScr()->flags2&wfDOWN)
3938 {
3939 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3940 }
3941 else if(currscr<MAPSCRS-16)
3942 {
3943 setCurrScr(currscr+16);
3944 }
3945
3946 break;
3947
3948 case left:
3949 if(warp && Map.CurrScr()->flags2&wfLEFT)
3950 {
3951 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3952 }
3953 else if(currscr&15)
3954 {
3955 setCurrScr(currscr-1);
3956 }
3957
3958 break;
3959
3960 case right:
3961 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3962 {
3963 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3964 }
3965 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3966 {
3967 setCurrScr(currscr+1);
3968 }
3969
3970 break;
3971 }
3972 }
3973 }
3974
3975 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3976 {
3977 switch(side)
3978 {
3979 case up:
3980 switch(door)
3981 {
3982 case dWALL:
3983 case dBOMB:
3984 case dWALK:
3985 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3986 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3987 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3988 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3989 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3990 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3991 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3992 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3993 break;
3994
3995 default:
3996 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3997 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3998 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3999 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4000 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4001 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4002 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4003 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4004 break;
4005 }
4006
4007 break;
4008
4009 case down:
4010 switch(door)
4011 {
4012 case dWALL:
4013 case dBOMB:
4014 case dWALK:
4015 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4016 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4017 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4018 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4019 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4020 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4021 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4022 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4023 break;
4024
4025 default:
4026 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4027 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4028 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4029 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4030 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4031 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4032 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4033 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4034 break;
4035 }
4036
4037 break;
4038
4039 case left:
4040 switch(door)
4041 {
4042 case dWALL:
4043 case dBOMB:
4044 case dWALK:
4045 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4046 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4047 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4048 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4049 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4050 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4051 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4052 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4053 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4054 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4055 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4056 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4057 break;
4058
4059 default:
4060 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4061 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4062 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4063 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4064 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4065 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4066 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4067 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4068 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4069 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4070 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4071 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4072 break;
4073 }
4074
4075 break;
4076
4077 case right:
4078 switch(door)
4079 {
4080 case dWALL:
4081 case dBOMB:
4082 case dWALK:
4083 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4084 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4085 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4086 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4087 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4088 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4089 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4090 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4091 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4092 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4093 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4094 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4095 break;
4096
4097 default:
4098 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4099 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4100 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4101 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4102 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4103 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4104 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4105 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4106 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4107 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4108 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4109 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4110 break;
4111 }
4112
4113 break;
4114 }
4115 }
4116 void zmap::DoPutDoorCommand(int side, int door, bool force)
4117 {
4118 if(!force && screens[currscr].door[side] == door)
4119 return;
4120 bool already_list = InListCommand();
4121 if(!already_list)
4122 StartListCommand();
4123 DoSetDoorCommand(currscr,side,door);
4124 if(door != dNONE)
4125 {
4126 word data[176] = {0};
4127 byte cset[176] = {0};
4128 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4129 for(int q = 0; q < 176; ++q)
4130 if(data[q])
4131 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4132 }
4133 if(!already_list)
4134 FinishListCommand();
4135 }
4136 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4137 {
4138 if(screens[scr].door[side] == door)
4139 return;
4140 screens[scr].door[side] = door;
4141 if(door != dNONE)
4142 {
4143 word data[176] = {0};
4144 byte cset[176] = {0};
4145 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4146 for(int q = 0; q < 176; ++q)
4147 if(data[q])
4148 {
4149 screens[scr].data[q] = data[q];
4150 screens[scr].cset[q] = cset[q];
4151 }
4152 }
4153 }
4154
4155 void list_command::execute()
4156 {
4157 for (auto command : commands)
4158 {
4159 command->execute();
4160 }
4161 }
4162
4163 void list_command::undo()
4164 {
4165 for (int i = commands.size() - 1; i >= 0; i--)
4166 {
4167 commands[i]->undo();
4168 }
4169 }
4170
4171 int list_command::size()
4172 {
4173 int s = 0;
4174 for (auto command : commands)
4175 {
4176 s += command->size();
4177 }
4178 return s;
4179 }
4180
4181 void set_combo_command::execute()
4182 {
4183 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4184 if(!mapscr_ptr) return;
4185
4186 mapscr_ptr->valid |= mVALID;
4187 if (combo != -1) mapscr_ptr->data[pos] = combo;
4188 mapscr_ptr->cset[pos] = cset;
4189 }
4190
4191 void set_combo_command::undo()
4192 {
4193 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4194 if(!mapscr_ptr) return;
4195 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4196 mapscr_ptr->cset[pos] = prev_cset;
4197 }
4198
4199 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4200 {
4201 std::array<int, 2> inita_arr;
4202 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4203 std::array<int, 8> initd_arr;
4204 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4205
4206 return {
4207 .x = ffc.x,
4208 .y = ffc.y,
4209 .vx = ffc.vx,
4210 .vy = ffc.vy,
4211 .ax = ffc.ax,
4212 .ay = ffc.ay,
4213 .data = ffc.data,
4214 .cset = ffc.cset,
4215 .delay = ffc.delay,
4216 .link = ffc.link,
4217 .script = ffc.script,
4218 .tw = ffc.txsz,
4219 .th = ffc.tysz,
4220 .ew = ffc.hit_width,
4221 .eh = ffc.hit_height,
4222 .flags = ffc.flags,
4223 .inita = inita_arr,
4224 .initd = initd_arr,
4225 };
4226 }
4227
4228 void set_ffc_command::execute()
4229 {
4230 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4231 if(!mapscr_ptr) return;
4232
4233 mapscr_ptr->valid |= mVALID;
4234 mapscr_ptr->ffcs[i].x = data.x;
4235 mapscr_ptr->ffcs[i].y = data.y;
4236 mapscr_ptr->ffcs[i].vx = data.vx;
4237 mapscr_ptr->ffcs[i].vy = data.vy;
4238 mapscr_ptr->ffcs[i].ax = data.ax;
4239 mapscr_ptr->ffcs[i].ay = data.ay;
4240 mapscr_ptr->ffcs[i].data = data.data;
4241 mapscr_ptr->ffcs[i].cset = data.cset;
4242 mapscr_ptr->ffcs[i].delay = data.delay;
4243 mapscr_ptr->ffcs[i].link = data.link;
4244 mapscr_ptr->ffcs[i].script = data.script;
4245 mapscr_ptr->ffcs[i].flags = data.flags;
4246 mapscr_ptr->ffEffectWidth(i, data.ew);
4247 mapscr_ptr->ffEffectHeight(i, data.eh);
4248 mapscr_ptr->ffTileWidth(i, data.tw);
4249 mapscr_ptr->ffTileHeight(i, data.th);
4250 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4251 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4252 mapscr_ptr->ffcCountMarkDirty();
4253 mapscr_ptr->ffcs[i].updateSolid();
4254 }
4255
4256 void set_ffc_command::undo()
4257 {
4258 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4259 if(!mapscr_ptr) return;
4260
4261 mapscr_ptr->ffcs[i].x = prev_data.x;
4262 mapscr_ptr->ffcs[i].y = prev_data.y;
4263 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4264 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4265 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4266 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4267 mapscr_ptr->ffcs[i].data = prev_data.data;
4268 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4269 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4270 mapscr_ptr->ffcs[i].link = prev_data.link;
4271 mapscr_ptr->ffcs[i].script = prev_data.script;
4272 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4273 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4274 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4275 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4276 mapscr_ptr->ffTileHeight(i, prev_data.th);
4277 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4278 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4279 mapscr_ptr->ffcCountMarkDirty();
4280 mapscr_ptr->ffcs[i].updateSolid();
4281 }
4282
4283 void set_flag_command::execute()
4284 {
4285 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4286 if(!mapscr_ptr) return;
4287
4288 mapscr_ptr->valid |= mVALID;
4289 mapscr_ptr->sflag[pos] = flag;
4290 }
4291
4292 void set_flag_command::undo()
4293 {
4294 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4295 if(!mapscr_ptr) return;
4296 mapscr_ptr->sflag[pos] = prev_flag;
4297 }
4298
4299 void set_door_command::execute()
4300 {
4301 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4302 if(!mapscr_ptr) return;
4303
4304 mapscr_ptr->valid |= mVALID;
4305 mapscr_ptr->door[side] = door;
4306 }
4307
4308 void set_door_command::undo()
4309 {
4310 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4311 }
4312
4313 void set_dcs_command::execute()
4314 {
4315 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4316 if(!mapscr_ptr) return;
4317
4318 mapscr_ptr->valid |= mVALID;
4319 mapscr_ptr->door_combo_set = dcs;
4320 }
4321
4322 void set_dcs_command::undo()
4323 {
4324 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4325 }
4326
4327 void paste_screen_command::execute()
4328 {
4329 perform(screen.get());
4330 }
4331
4332 void paste_screen_command::undo()
4333 {
4334 if (prev_screens.size() > 1)
4335 {
4336 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4337 ASSERT(prev_screens.size() == 128);
4338 for (int i = 0; i < 128; i++)
4339 {
4340 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4341 // TODO: why not just this?
4342 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4343 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4344 }
4345 return;
4346 }
4347
4348 perform(prev_screens[0].get());
4349 }
4350
4351 int paste_screen_command::size()
4352 {
4353 return prev_screens.size() + 1;
4354 }
4355
4356 void paste_screen_command::perform(mapscr* to)
4357 {
4358 if (to)
4359 {
4360 switch (type) {
4361 case ScreenAll: Map.PasteAll(*to); break;
4362 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4363 case ScreenData: Map.PasteScreenData(*to); break;
4364 case ScreenDoors: Map.PasteDoors(*to); break;
4365 case ScreenEnemies: Map.PasteEnemies(*to); break;
4366 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4367 case ScreenGuy: Map.PasteGuy(*to); break;
4368 case ScreenLayers: Map.PasteLayers(*to); break;
4369 case ScreenPalette: Map.PastePalette(*to); break;
4370 case ScreenPartial: Map.Paste(*to); break;
4371 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4372 case ScreenRoom: Map.PasteRoom(*to); break;
4373 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4374 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4375 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4376 case ScreenWarps: Map.PasteWarps(*to); break;
4377 }
4378 }
4379 else
4380 {
4381 Map.clearscr(view_scr);
4382 }
4383 refresh(rALL);
4384 }
4385
4386 void set_screen_command::execute()
4387 {
4388 if (screen)
4389 {
4390 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4391 }
4392 else
4393 {
4394 Map.clearscr(view_scr);
4395 }
4396 refresh(rALL);
4397 }
4398
4399 void set_screen_command::undo()
4400 {
4401 if (prev_screen)
4402 {
4403 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4404 }
4405 else
4406 {
4407 Map.clearscr(view_scr);
4408 }
4409 refresh(rALL);
4410 }
4411
4412 int set_screen_command::size()
4413 {
4414 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4415 }
4416
4417 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4418
4419 void tile_grid_draw_command::execute()
4420 {
4421 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4422 }
4423
4424 void tile_grid_draw_command::undo()
4425 {
4426 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4427 }
4428
4429 static std::shared_ptr<list_command> current_list_command;
4430 void zmap::StartListCommand()
4431 {
4432 ASSERT(!current_list_command);
4433 current_list_command.reset(new list_command);
4434 }
4435
4436 void zmap::FinishListCommand()
4437 {
4438 if (current_list_command->commands.size() == 1)
4439 {
4440 undo_stack.push_back(current_list_command->commands[0]);
4441 }
4442 else if (current_list_command->commands.size() > 1)
4443 {
4444 undo_stack.push_back(current_list_command);
4445 }
4446 CapCommandHistory();
4447 current_list_command = nullptr;
4448 }
4449
4450 void zmap::RevokeListCommand()
4451 {
4452 current_list_command->undo();
4453 current_list_command = nullptr;
4454 }
4455
4456 bool zmap::InListCommand() const
4457 {
4458 return current_list_command ? true : false;
4459 }
4460
4461 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4462 {
4463 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4464 if (!skip_execute) command->execute();
4465 if (current_list_command)
4466 {
4467 current_list_command->commands.push_back(command);
4468 if (current_list_command->commands.size() == 1)
4469 {
4470 current_list_command->view_map = command->view_map;
4471 current_list_command->view_scr = command->view_scr;
4472 }
4473 }
4474 else
4475 {
4476 undo_stack.push_back(command);
4477 CapCommandHistory();
4478 }
4479 saved = false;
4480 }
4481
4482 void zmap::UndoCommand()
4483 {
4484 if (undo_stack.size() <= 0) return;
4485
4486 // If not currently looking at the associated screen, first change the view
4487 // and wait for the next call to actually undo this command.
4488 auto command = undo_stack.back();
4489 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4490 {
4491 setCurrentView(command->view_map, command->view_scr);
4492 return;
4493 }
4494
4495 command->undo();
4496 redo_stack.push(command);
4497 undo_stack.pop_back();
4498 saved = false;
4499 }
4500
4501 void zmap::RedoCommand()
4502 {
4503 if (redo_stack.size() <= 0) return;
4504
4505 // If not currently looking at the associated screen, first change the view
4506 // and wait for the next call to actually execute this command.
4507 auto command = redo_stack.top();
4508 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4509 {
4510 setCurrentView(command->view_map, command->view_scr);
4511 return;
4512 }
4513
4514 command->execute();
4515 undo_stack.push_back(command);
4516 redo_stack.pop();
4517 saved = false;
4518 }
4519
4520 9 void zmap::ClearCommandHistory()
4521 {
4522 9 current_list_command = nullptr;
4523 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4524 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4525 9 }
4526
4527 // Extra amount is from mapscr's vectors.
4528 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4529 // Allow the undo system to use roughly 100 MB of memory.
4530 // This doesn't count the memory used by commands that don't store a mapscr,
4531 // but that should be negligible.
4532 9 static int max_command_size = 100e6 / size_of_mapscr;
4533 void zmap::CapCommandHistory()
4534 {
4535 int size;
4536 do
4537 {
4538 size = 0;
4539 for (auto command : undo_stack)
4540 {
4541 size += command->size();
4542 }
4543 if (size > max_command_size) undo_stack.pop_front();
4544 } while (size > max_command_size);
4545 }
4546
4547 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4548 {
4549 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4550 if(!mapscr_ptr) return;
4551 std::shared_ptr<set_combo_command> command(new set_combo_command);
4552 command->view_map = currmap;
4553 command->view_scr = currscr;
4554 command->map = map;
4555 command->scr = scr;
4556 command->pos = pos;
4557 command->combo = combo;
4558 command->cset = cset;
4559 command->prev_combo = mapscr_ptr->data[pos];
4560 command->prev_cset = mapscr_ptr->cset[pos];
4561 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4562 {
4563 // nothing to do...
4564 return;
4565 }
4566
4567 ExecuteCommand(command);
4568 }
4569
4570 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4571 {
4572 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4573 if(!mapscr_ptr) return;
4574
4575 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4576
4577 std::array<int, 2> inita_arr;
4578 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4579 std::array<int, 8> initd_arr;
4580 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4581
4582 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4583
4584 command->view_map = currmap;
4585 command->view_scr = currscr;
4586 command->map = map;
4587 command->scr = scr;
4588 command->i = i;
4589 command->data = data;
4590 command->prev_data = prev_data;
4591 if (data == prev_data)
4592 {
4593 // nothing to do...
4594 return;
4595 }
4596
4597 ExecuteCommand(command);
4598 }
4599
4600 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4601 {
4602 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4603 if(!mapscr_ptr) return;
4604 std::shared_ptr<set_flag_command> command(new set_flag_command);
4605 command->view_map = currmap;
4606 command->view_scr = currscr;
4607 command->map = map;
4608 command->scr = scr;
4609 command->pos = pos;
4610 command->flag = flag;
4611 command->prev_flag = mapscr_ptr->sflag[pos];
4612 if (command->flag == command->prev_flag)
4613 {
4614 // nothing to do...
4615 return;
4616 }
4617
4618 ExecuteCommand(command);
4619 }
4620
4621 void zmap::DoSetDoorCommand(int scr, int side, int door)
4622 {
4623 if(screens[scr].door[side] == door)
4624 return;
4625 std::shared_ptr<set_door_command> command(new set_door_command);
4626 command->view_map = currmap;
4627 command->view_scr = scr;
4628 command->side = side;
4629 command->door = door;
4630 command->prev_door = screens[scr].door[side];
4631
4632 ExecuteCommand(command);
4633 }
4634 void zmap::DoSetDCSCommand(int dcs)
4635 {
4636 if(screens[currscr].door_combo_set == dcs)
4637 return;
4638 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4639 command->view_map = currmap;
4640 command->view_scr = currscr;
4641 command->dcs = dcs;
4642 command->prev_dcs = screens[currscr].door_combo_set;
4643
4644 ExecuteCommand(command);
4645 }
4646
4647 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4648 {
4649 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4650 command->view_map = currmap;
4651 command->view_scr = currscr;
4652 command->type = type;
4653 command->data = data;
4654 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4655
4656 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4657 {
4658 for (int i=0; i < 128; i++)
4659 {
4660 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4661 }
4662 }
4663 else
4664 {
4665 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4666 }
4667
4668 ExecuteCommand(command);
4669 }
4670
4671 void zmap::DoClearScreenCommand()
4672 {
4673 std::shared_ptr<set_screen_command> command(new set_screen_command);
4674 command->view_map = currmap;
4675 command->view_scr = currscr;
4676 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4677 command->screen = std::shared_ptr<mapscr>(nullptr);
4678
4679 ExecuteCommand(command);
4680 }
4681
4682 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4683 {
4684 std::shared_ptr<set_screen_command> command(new set_screen_command);
4685 command->view_map = currmap;
4686 command->view_scr = currscr;
4687 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4688 Template(floorcombo, floorcset, scr);
4689 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4690
4691 ExecuteCommand(command, true);
4692 }
4693
4694 void zmap::Copy()
4695 {
4696 if(screens[currscr].valid&mVALID)
4697 {
4698 copy_mapscr(&copymapscr, &screens[currscr]);
4699 //copymapscr=screens[currscr];
4700 can_paste=true;
4701 copymap=currmap;
4702 copyscr=currscr;
4703 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4704 copyffc = -1;
4705 }
4706 }
4707
4708 void zmap::CopyFFC(int32_t n)
4709 {
4710 if(screens[currscr].valid&mVALID)
4711 {
4712 copy_mapscr(&copymapscr, &screens[currscr]);
4713 // Can't paste the screen itself
4714 can_paste = false;
4715 copymap=currmap;
4716 copyscr=currscr;
4717 copyffc = n;
4718 }
4719 }
4720
4721 void zmap::Paste(const mapscr& copymapscr)
4722 {
4723 if(can_paste)
4724 {
4725 int32_t oldcolor=getcolor();
4726
4727 if(!(screens[currscr].valid&mVALID))
4728 {
4729 screens[currscr].valid |= mVALID;
4730 screens[currscr].color = copymapscr.color;
4731 }
4732
4733 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4734
4735 for(int32_t i=0; i<4; i++)
4736 {
4737 screens[currscr].door[i]=copymapscr.door[i];
4738 }
4739
4740 for(int32_t i=0; i<176; i++)
4741 {
4742 screens[currscr].data[i] = copymapscr.data[i];
4743 screens[currscr].cset[i] = copymapscr.cset[i];
4744 screens[currscr].sflag[i] = copymapscr.sflag[i];
4745 }
4746
4747 int32_t newcolor=getcolor();
4748 loadlvlpal(newcolor);
4749
4750 if(newcolor!=oldcolor)
4751 {
4752 rebuild_trans_table();
4753 }
4754
4755 saved=false;
4756 }
4757 }
4758
4759 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4760 {
4761 if(can_paste)
4762 {
4763 screens[currscr].undercombo = copymapscr.undercombo;
4764 screens[currscr].undercset = copymapscr.undercset;
4765 saved=false;
4766 }
4767 }
4768
4769 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4770 {
4771 if(can_paste)
4772 {
4773 for(int32_t i=0; i<128; i++)
4774 {
4775 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4776 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4777 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4778 }
4779
4780 saved=false;
4781 }
4782 }
4783
4784 // TODO const mapscr& copymapscr
4785 void zmap::PasteFFCombos(mapscr& copymapscr)
4786 {
4787 if(can_paste)
4788 {
4789 word c = copymapscr.numFFC();
4790 for(word i=0; i<c; i++)
4791 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4792 for(word i = c; i < MAXFFCS; ++i)
4793 screens[currscr].ffcs[i].clear();
4794
4795 saved=false;
4796 }
4797 }
4798
4799 void zmap::PasteWarps(const mapscr& copymapscr)
4800 {
4801 if(can_paste)
4802 {
4803 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4804
4805 for(int32_t i=0; i<4; i++)
4806 {
4807 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4808 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4809 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4810 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4811 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4812 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4813 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4814 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4815 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4816 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4817 }
4818
4819 saved=false;
4820 }
4821 }
4822
4823 void zmap::PasteScreenData(const mapscr& copymapscr)
4824 {
4825 if(can_paste)
4826 {
4827 screens[currscr].csensitive = copymapscr.csensitive;
4828 screens[currscr].oceansfx = copymapscr.oceansfx;
4829 screens[currscr].bosssfx = copymapscr.bosssfx;
4830 screens[currscr].secretsfx = copymapscr.secretsfx;
4831 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4832 screens[currscr].flags = copymapscr.flags;
4833 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4834 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4835 screens[currscr].flags3 = copymapscr.flags3;
4836 screens[currscr].flags4 = copymapscr.flags4;
4837 screens[currscr].flags5 = copymapscr.flags5;
4838 screens[currscr].flags6 = copymapscr.flags6;
4839 screens[currscr].flags7 = copymapscr.flags7;
4840 screens[currscr].flags8 = copymapscr.flags8;
4841 screens[currscr].flags9 = copymapscr.flags9;
4842 screens[currscr].flags10 = copymapscr.flags10;
4843 screens[currscr].item = copymapscr.item;
4844 screens[currscr].hasitem = copymapscr.hasitem;
4845 screens[currscr].itemx = copymapscr.itemx;
4846 screens[currscr].itemy = copymapscr.itemy;
4847 screens[currscr].nextmap = copymapscr.nextmap;
4848 screens[currscr].nextscr = copymapscr.nextscr;
4849 screens[currscr].nocarry = copymapscr.nocarry;
4850 screens[currscr].noreset = copymapscr.noreset;
4851 screens[currscr].path[0] = copymapscr.path[0];
4852 screens[currscr].path[1] = copymapscr.path[1];
4853 screens[currscr].path[2] = copymapscr.path[2];
4854 screens[currscr].path[3] = copymapscr.path[3];
4855 screens[currscr].pattern = copymapscr.pattern;
4856 screens[currscr].exitdir = copymapscr.exitdir;
4857 screens[currscr].enemyflags = copymapscr.enemyflags;
4858 screens[currscr].screen_midi = copymapscr.screen_midi;
4859 screens[currscr].stairx = copymapscr.stairx;
4860 screens[currscr].stairy = copymapscr.stairy;
4861 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4862 saved=false;
4863 }
4864 }
4865
4866 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4867 {
4868 if(can_paste)
4869 {
4870 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4871 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4872 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4873
4874 for(int32_t i=0; i<4; i++)
4875 {
4876 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4877 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4878 }
4879
4880 saved=false;
4881 }
4882 }
4883
4884 void zmap::PasteDoors(const mapscr& copymapscr)
4885 {
4886 if(can_paste)
4887 {
4888 for(int32_t i=0; i<4; i++)
4889 screens[currscr].door[i] = copymapscr.door[i];
4890
4891 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4892 saved=false;
4893 }
4894 }
4895
4896 void zmap::PasteLayers(const mapscr& copymapscr)
4897 {
4898 if(can_paste)
4899 {
4900 for(int32_t i=0; i<6; i++)
4901 {
4902 screens[currscr].layermap[i] = copymapscr.layermap[i];
4903 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4904 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4905 }
4906
4907 saved=false;
4908 }
4909 }
4910
4911 void zmap::PasteRoom(const mapscr& copymapscr)
4912 {
4913 if(can_paste)
4914 {
4915 screens[currscr].room = copymapscr.room;
4916 screens[currscr].catchall = copymapscr.catchall;
4917 saved=false;
4918 }
4919 }
4920
4921 void zmap::PasteGuy(const mapscr& copymapscr)
4922 {
4923 if(can_paste)
4924 {
4925 screens[currscr].guy = copymapscr.guy;
4926 screens[currscr].guytile = copymapscr.guytile;
4927 screens[currscr].guycs = copymapscr.guycs;
4928 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4929 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4930 screens[currscr].str = copymapscr.str;
4931 saved=false;
4932 }
4933 }
4934
4935 void zmap::PastePalette(const mapscr& copymapscr)
4936 {
4937 if(can_paste)
4938 {
4939 int32_t oldcolor=getcolor();
4940 screens[currscr].color = copymapscr.color;
4941 int32_t newcolor=getcolor();
4942 loadlvlpal(newcolor);
4943
4944 screens[currscr].valid|=mVALID;
4945
4946 if(newcolor!=oldcolor)
4947 {
4948 rebuild_trans_table();
4949 }
4950
4951 saved=false;
4952 }
4953 }
4954
4955 void zmap::PasteAll(const mapscr& copymapscr)
4956 {
4957 if(can_paste)
4958 {
4959 int32_t oldcolor=getcolor();
4960 copy_mapscr(&screens[currscr], &copymapscr);
4961 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4962 //screens[currscr]=copymapscr;
4963 int32_t newcolor=getcolor();
4964 loadlvlpal(newcolor);
4965
4966 screens[currscr].valid|=mVALID;
4967
4968 if(newcolor!=oldcolor)
4969 {
4970 rebuild_trans_table();
4971 }
4972
4973 saved=false;
4974 }
4975 }
4976
4977
4978 void zmap::PasteToAll(const mapscr& copymapscr)
4979 {
4980 if(can_paste)
4981 {
4982 int32_t oldcolor=getcolor();
4983
4984 for(int32_t x=0; x<128; x++)
4985 {
4986 if(!(screens[x].valid&mVALID))
4987 {
4988 screens[x].valid |= mVALID;
4989 screens[x].color = copymapscr.color;
4990 }
4991
4992 for(int32_t i=0; i<176; i++)
4993 {
4994 screens[x].data[i] = copymapscr.data[i];
4995 screens[x].cset[i] = copymapscr.cset[i];
4996 screens[x].sflag[i] = copymapscr.sflag[i];
4997 }
4998 }
4999
5000 int32_t newcolor=getcolor();
5001 loadlvlpal(newcolor);
5002
5003 if(!(screens[currscr].valid&mVALID))
5004 {
5005 newcolor=-1;
5006 }
5007
5008 if(newcolor!=oldcolor)
5009 {
5010 rebuild_trans_table();
5011 }
5012
5013 saved=false;
5014 }
5015 }
5016
5017 void zmap::PasteAllToAll(const mapscr& copymapscr)
5018 {
5019 if(can_paste)
5020 {
5021 int32_t oldcolor=getcolor();
5022
5023 for(int32_t x=0; x<128; x++)
5024 {
5025 copy_mapscr(&screens[x], &copymapscr);
5026 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5027 //screens[x]=copymapscr;
5028 }
5029
5030 int32_t newcolor=getcolor();
5031 loadlvlpal(newcolor);
5032
5033 if(!(screens[currscr].valid&mVALID))
5034 {
5035 newcolor=-1;
5036 }
5037
5038 if(newcolor!=oldcolor)
5039 {
5040 rebuild_trans_table();
5041 }
5042
5043 saved=false;
5044 }
5045 }
5046
5047 void zmap::PasteEnemies(const mapscr& copymapscr)
5048 {
5049 if(can_paste)
5050 {
5051 for(int32_t i=0; i<10; i++)
5052 screens[currscr].enemy[i]=copymapscr.enemy[i];
5053 }
5054 }
5055
5056 void zmap::setCopyFFC(int32_t n)
5057 {
5058 copyffc = n;
5059 }
5060
5061 void zmap::update_combo_cycling()
5062 {
5063 if(!prv_mode||!prv_cmbcycle)
5064 {
5065 return;
5066 }
5067
5068 int32_t x;
5069 int32_t newdata[176];
5070 int32_t newcset[176];
5071 bool restartanim[MAXCOMBOS] = {0};
5072
5073 for(int32_t i=0; i<176; i++)
5074 {
5075 newdata[i]=-1;
5076 newcset[i]=-1;
5077
5078 x=prvscr.data[i];
5079
5080 //time to restart
5081 if((combobuf[x].aclk>=combobuf[x].speed) &&
5082 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5083 (combobuf[x].nextcombo!=0))
5084 {
5085 newdata[i]=combobuf[x].nextcombo;
5086 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5087 newcset[i]=combobuf[x].nextcset;
5088 int32_t c = newdata[i];
5089
5090 if(combobuf[c].animflags & AF_CYCLE)
5091 {
5092 restartanim[c]=true;
5093 }
5094 }
5095 }
5096
5097 for(int32_t i=0; i<176; i++)
5098 {
5099 x=prvscr.data[i];
5100
5101 //time to restart
5102 if((combobuf[x].aclk>=combobuf[x].speed) &&
5103 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5104 (combobuf[x].nextcombo!=0))
5105 {
5106 newdata[i]=combobuf[x].nextcombo;
5107 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5108 newcset[i]=combobuf[x].nextcset;
5109 int32_t c = newdata[i];
5110
5111 if(combobuf[c].animflags & AF_CYCLE)
5112 {
5113 restartanim[c]=true;
5114 }
5115 }
5116 }
5117
5118 for(int32_t i=0; i<176; i++)
5119 {
5120 if(newdata[i]==-1)
5121 continue;
5122
5123 prvscr.data[i]=newdata[i];
5124 prvscr.cset[i]=newcset[i];
5125 }
5126
5127 word maxffc = prvscr.numFFC();
5128 for(word i=0; i<maxffc; i++)
5129 {
5130 ffcdata& ffc = prvscr.ffcs[i];
5131 newcombo const& cmb = combobuf[ffc.data];
5132
5133 //time to restart
5134 if((cmb.aclk>=cmb.speed) &&
5135 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5136 (cmb.nextcombo!=0))
5137 {
5138 ffc.data = cmb.nextcombo;
5139 if(!(cmb.animflags & AF_CYCLENOCSET))
5140 ffc.cset=cmb.nextcset;
5141
5142 if(combobuf[ffc.data].animflags & AF_CYCLE)
5143 {
5144 restartanim[ffc.data]=true;
5145 }
5146 prvscr.ffcs[i].data = ffc.data;
5147 prvscr.ffcs[i].cset=ffc.cset;
5148 }
5149 }
5150
5151
5152 if(get_qr(qr_CMBCYCLELAYERS))
5153 {
5154 for(int32_t j=0; j<6; j++)
5155 {
5156 if(!prvlayers[j].valid)
5157 continue;
5158
5159 for(int32_t i=0; i<176; i++)
5160 {
5161 newdata[i]=-1;
5162 newcset[i]=-1;
5163
5164 x=(prvlayers[j]).data[i];
5165
5166 //time to restart
5167 if((combobuf[x].aclk>=combobuf[x].speed) &&
5168 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5169 (combobuf[x].nextcombo!=0))
5170 {
5171 newdata[i]=combobuf[x].nextcombo;
5172 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5173 newcset[i]=combobuf[x].nextcset;
5174 int32_t c = newdata[i];
5175
5176 if(combobuf[c].animflags & AF_CYCLE)
5177 {
5178 restartanim[c]=true;
5179 }
5180 }
5181 }
5182
5183 for(int32_t i=0; i<176; i++)
5184 {
5185 x=(prvlayers[j]).data[i];
5186
5187 //time to restart
5188 if((combobuf[x].aclk>=combobuf[x].speed) &&
5189 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5190 (combobuf[x].nextcombo!=0))
5191 {
5192 newdata[i]=combobuf[x].nextcombo;
5193 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5194 newcset[i]=combobuf[x].nextcset;
5195 int32_t c = newdata[i];
5196
5197 if(combobuf[c].animflags & AF_CYCLE)
5198 {
5199 restartanim[c]=true;
5200 }
5201 }
5202 }
5203
5204 for(int32_t i=0; i<176; i++)
5205 {
5206 if(newdata[i]==-1)
5207 continue;
5208
5209 prvlayers[j].data[i]=newdata[i];
5210 prvlayers[j].cset[i]=newcset[i];
5211 }
5212 }
5213 }
5214
5215 for(int32_t i=0; i<MAXCOMBOS; i++)
5216 {
5217 if(restartanim[i])
5218 {
5219 combobuf[i].tile = combobuf[i].o_tile;
5220 combobuf[i].cur_frame=0;
5221 combobuf[i].aclk = 0;
5222 }
5223 }
5224 }
5225
5226 void zmap::update_freeform_combos()
5227 {
5228 if(!prv_mode||!prv_cmbcycle)
5229 {
5230 return;
5231 }
5232
5233 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5234 word maxffc = prvscr.numFFC();
5235 for(int32_t i=0; i<maxffc; i++)
5236 {
5237 if(!(prvscr.ffcs[i].flags&ffCHANGER) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffSTATIONARY))
5238 {
5239 for(int32_t j=0; j<maxffc; j++)
5240 {
5241 if(i!=j)
5242 {
5243 if(prvscr.ffcs[j].flags&ffCHANGER && prvscr.ffcs[j].data != 0)
5244 {
5245 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5246 {
5247 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5248 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5249 {
5250 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5251 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5252 if(prvscr.ffcs[j].flags&ffCHANGETHIS)
5253 {
5254 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5255 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5256 }
5257
5258 if(prvscr.ffcs[j].flags&ffCHANGENEXT)
5259 prvscr.ffcs[i].data += 1;
5260
5261 if(prvscr.ffcs[j].flags&ffCHANGEPREV)
5262 prvscr.ffcs[i].data -= 1;
5263
5264 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5265 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5266 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5267
5268 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5269 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5270 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5271 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5272
5273 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5274 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5275 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5276 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5277 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5278
5279 if(prvscr.ffcs[i].flags&ffCARRYOVER)
5280 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffCARRYOVER;
5281 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5282
5283 prvscr.ffcs[i].flags&=~ffCHANGER;
5284 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5285 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5286
5287 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5288 {
5289 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5290 }
5291
5292 if((prvscr.ffcs[j].flags&ffSWAPNEXT)||(prvscr.ffcs[j].flags&ffSWAPPREV))
5293 {
5294 int32_t k=0;
5295
5296 if(prvscr.ffcs[j].flags&ffSWAPNEXT)
5297 k=j<(MAXFFCS-1)?j+1:0;
5298
5299 if(prvscr.ffcs[j].flags&ffSWAPPREV)
5300 k=j>0?j-1:(MAXFFCS-1);
5301
5302 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5303 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5304 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5305 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5306 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5307 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5308 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5309 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5310 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5311 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5312 }
5313 }
5314 }
5315 }
5316 }
5317 }
5318
5319 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5320 {
5321 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5322 {
5323 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5324 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5325 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5326 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5327 }
5328 else
5329 {
5330 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5331 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5332 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5333 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5334 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5335 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5336
5337 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5338 {
5339 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5340
5341 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5342
5343 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5344
5345 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5346 }
5347 }
5348 }
5349 else
5350 {
5351 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5352 prvscr.ffcs[i].delay--;
5353 }
5354
5355 if(prvscr.ffcs[i].x<-32)
5356 {
5357 if(prvscr.flags6&fWRAPAROUNDFF)
5358 {
5359 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5360 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5361 }
5362 else
5363 {
5364 prvscr.ffcs[i].data = 0;
5365 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5366 }
5367 }
5368
5369 if(prvscr.ffcs[i].y<-32)
5370 {
5371 if(prvscr.flags6&fWRAPAROUNDFF)
5372 {
5373 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5374 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5375 }
5376 else
5377 {
5378 prvscr.ffcs[i].data = 0;
5379 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5380 }
5381 }
5382
5383 if(prvscr.ffcs[i].x>=288)
5384 {
5385 if(prvscr.flags6&fWRAPAROUNDFF)
5386 {
5387 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5388 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5389 }
5390 else
5391 {
5392 prvscr.ffcs[i].data = 0;
5393 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5394 }
5395 }
5396
5397 if(prvscr.ffcs[i].y>=208)
5398 {
5399 if(prvscr.flags6&fWRAPAROUNDFF)
5400 {
5401 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5402 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5403 }
5404 else
5405 {
5406 prvscr.ffcs[i].data = 0;
5407 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5408 }
5409 }
5410
5411 }
5412 }
5413 }
5414
5415 void zmap::goto_dmapscr(int dmap, int scr)
5416 {
5417 setCurrMap(DMaps[dmap].map);
5418 setCurrScr(scr+DMaps[dmap].xoff);
5419 }
5420 void zmap::goto_mapscr(int map, int scr)
5421 {
5422 setCurrMap(map);
5423 setCurrScr(scr);
5424 }
5425
5426 void zmap::dowarp(int32_t type, int32_t index)
5427 {
5428 set_warpback();
5429 if(type==0)
5430 {
5431
5432 int32_t dmap=screens[currscr].tilewarpdmap[index];
5433 int32_t scr=screens[currscr].tilewarpscr[index];
5434
5435 switch(screens[currscr].tilewarptype[index])
5436 {
5437 case wtCAVE:
5438 case wtNOWARP:
5439 break;
5440
5441 default:
5442 goto_dmapscr(dmap, scr);
5443 break;
5444 }
5445 }
5446 else if(type==1)
5447 {
5448 int32_t dmap=screens[currscr].sidewarpdmap[index];
5449 int32_t scr=screens[currscr].sidewarpscr[index];
5450
5451 switch(screens[currscr].sidewarptype[index])
5452 {
5453 case wtCAVE:
5454 case wtNOWARP:
5455 break;
5456
5457 default:
5458 goto_dmapscr(dmap, scr);
5459 break;
5460 }
5461 }
5462 }
5463
5464 extern int32_t prv_twon;
5465
5466 void zmap::prv_dowarp(int32_t type, int32_t index)
5467 {
5468 if(type==0)
5469 {
5470
5471 int32_t dmap=prvscr.tilewarpdmap[index];
5472 int32_t scr=prvscr.tilewarpscr[index];
5473
5474 switch(prvscr.tilewarptype[index])
5475 {
5476 case wtCAVE:
5477 case wtNOWARP:
5478 break;
5479
5480 default:
5481 //setCurrMap(DMaps[dmap].map);
5482 //setCurrScr(scr+DMaps[dmap].xoff);
5483 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5484 loadlvlpal(getcolor());
5485 rebuild_trans_table();
5486 //prv_cmbcycle=0;
5487 break;
5488 }
5489 }
5490 else if(type==1)
5491 {
5492 int32_t dmap=prvscr.sidewarpdmap[index];
5493 int32_t scr=prvscr.sidewarpscr[index];
5494
5495 switch(prvscr.sidewarptype[index])
5496 {
5497 case wtCAVE:
5498 case wtNOWARP:
5499 break;
5500
5501 default:
5502 //setCurrMap(DMaps[dmap].map);
5503 //setCurrScr(scr+DMaps[dmap].xoff);
5504 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5505 loadlvlpal(getcolor());
5506 rebuild_trans_table();
5507 //prv_cmbcycle=0;
5508 break;
5509 }
5510 }
5511
5512 if(prv_twon)
5513 {
5514 prv_time=get_prvscr()->timedwarptics;
5515 }
5516
5517 //also reset FFC information (so that changers will work correctly) -DD
5518 memset(ffposx,0xFF,sizeof(int16_t)*32);
5519 memset(ffposy,0xFF,sizeof(int16_t)*32);
5520 memset(ffprvx,0xFF,sizeof(float)*32);
5521 memset(ffprvy,0xFF,sizeof(float)*32);
5522 }
5523
5524 void zmap::dowarp2(int32_t ring,int32_t index)
5525 {
5526 set_warpback();
5527 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5528 }
5529
5530 void zmap::set_warpback()
5531 {
5532 warpbackmap = currmap;
5533 warpbackscreen = currscr;
5534 }
5535 bool zmap::has_warpback()
5536 {
5537 return warpbackmap && warpbackscreen
5538 && !(warpbackmap == currmap && warpbackscreen == currscr);
5539 }
5540 void zmap::warpback()
5541 {
5542 if(!has_warpback())
5543 return;
5544 int m = currmap, s = currscr;
5545 goto_mapscr(*warpbackmap, *warpbackscreen);
5546 warpbackmap = m;
5547 warpbackscreen = s;
5548 }
5549
5550 /******************************/
5551 /******** ZQuest stuff ********/
5552 /******************************/
5553
5554 bool save_msgstrs(const char *path)
5555 {
5556 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5557
5558 if(!f)
5559 {
5560 return false;
5561 }
5562
5563 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5564 {
5565 pack_fclose(f);
5566 return true;
5567 }
5568
5569 pack_fclose(f);
5570 return false;
5571 }
5572
5573 1 bool save_strings_tsv(const char *path)
5574 {
5575 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5576
5577
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5578 {
5579 return false;
5580 }
5581
5582
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5583 {
5584 1 pack_fclose(f);
5585 1 return true;
5586 }
5587
5588 pack_fclose(f);
5589 return false;
5590 1 }
5591
5592 bool save_msgstrs_text(const char *path)
5593 {
5594 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5595
5596 if(!f)
5597 {
5598 return false;
5599 }
5600
5601 if(writestrings_text(f)==0)
5602 {
5603 pack_fclose(f);
5604 return true;
5605 }
5606
5607 pack_fclose(f);
5608 return false;
5609 }
5610
5611 bool load_msgstrs(const char *path, int32_t startstring)
5612 {
5613 //these are here to bypass compiler warnings about unused arguments
5614 startstring=startstring;
5615
5616 dword section_id;
5617 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5618
5619 if(!f)
5620 {
5621 return false;
5622 }
5623
5624 if(!p_mgetl(&section_id,f))
5625 {
5626 return false;
5627 }
5628
5629 if(section_id==ID_STRINGS)
5630 {
5631 if(readstrings(f, &header)==0)
5632 {
5633 pack_fclose(f);
5634 return true;
5635 }
5636 else
5637 {
5638 pack_fclose(f);
5639 return false;
5640 }
5641 }
5642
5643 pack_fclose(f);
5644 return false;
5645 }
5646
5647 bool load_strings_tsv(const char *path)
5648 {
5649 try
5650 {
5651 parse_strings_tsv(util::read_text_file(path));
5652 }
5653 catch (std::exception& ex)
5654 {
5655 InfoDialog("Import .tsv Error", ex.what()).show();
5656 return false;
5657 }
5658 return true;
5659 }
5660
5661 bool save_pals(const char *path)
5662 {
5663 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5664
5665 if(!f)
5666 {
5667 return false;
5668 }
5669
5670 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5671 {
5672 pack_fclose(f);
5673 return true;
5674 }
5675
5676 pack_fclose(f);
5677 return false;
5678 }
5679
5680 bool load_pals(const char *path, int32_t startcset)
5681 {
5682 dword section_id;
5683 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5684
5685 if(!f)
5686 {
5687 return false;
5688 }
5689
5690 if(!p_mgetl(&section_id,f))
5691 {
5692 return false;
5693 }
5694
5695 if(section_id==ID_CSETS)
5696 {
5697 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5698 {
5699 pack_fclose(f);
5700 loadlvlpal(Color);
5701 return true;
5702 }
5703 else
5704 {
5705 pack_fclose(f);
5706 return false;
5707 }
5708 }
5709
5710 return false;
5711 }
5712
5713 bool save_dmaps(const char *path)
5714 {
5715 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5716
5717 if(!f)
5718 {
5719 return false;
5720 }
5721
5722 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5723 {
5724 pack_fclose(f);
5725 return true;
5726 }
5727
5728 pack_fclose(f);
5729 return false;
5730 }
5731
5732 bool load_dmaps(const char *path, int32_t startdmap)
5733 {
5734 dword section_id;
5735 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5736
5737 if(!f)
5738 {
5739 return false;
5740 }
5741
5742 if(!p_mgetl(&section_id,f))
5743 {
5744 return false;
5745 }
5746
5747 if(section_id==ID_DMAPS)
5748 {
5749 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5750 {
5751 pack_fclose(f);
5752 return true;
5753 }
5754 else
5755 {
5756 pack_fclose(f);
5757 return false;
5758 }
5759 }
5760
5761 return false;
5762 }
5763 bool save_combos(const char *path)
5764 {
5765 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5766
5767 if(!f)
5768 {
5769 return false;
5770 }
5771
5772 reset_combo_animations();
5773 reset_combo_animations2();
5774
5775 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5776 {
5777 pack_fclose(f);
5778 return true;
5779 }
5780
5781 pack_fclose(f);
5782 return false;
5783 }
5784
5785 bool load_combos(const char *path, int32_t startcombo)
5786 {
5787 dword section_id;
5788 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5789
5790 if(!f)
5791 {
5792 return false;
5793 }
5794
5795 if(!p_mgetl(&section_id,f))
5796 {
5797 return false;
5798 }
5799
5800 if(section_id==ID_COMBOS)
5801 {
5802 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5803 {
5804 pack_fclose(f);
5805 return true;
5806 }
5807 else
5808 {
5809 pack_fclose(f);
5810 // init_combos(true, &header);
5811 return false;
5812 }
5813 }
5814
5815 return false;
5816 }
5817
5818 bool save_tiles(const char *path)
5819 {
5820 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5821
5822 if(!f)
5823 {
5824 return false;
5825 }
5826
5827 // reset_combo_animations();
5828 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5829 {
5830 pack_fclose(f);
5831 return true;
5832 }
5833
5834 pack_fclose(f);
5835 return false;
5836 }
5837
5838 bool load_tiles(const char *path, int32_t starttile)
5839 {
5840 dword section_id;
5841 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5842
5843 if(!f)
5844 {
5845 return false;
5846 }
5847
5848 if(!p_mgetl(&section_id,f))
5849 {
5850 return false;
5851 }
5852
5853 if(section_id==ID_TILES)
5854 {
5855 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5856 {
5857 pack_fclose(f);
5858 return true;
5859 }
5860 else
5861 {
5862 pack_fclose(f);
5863 init_tiles(true, &header);
5864 return false;
5865 }
5866 }
5867
5868 return false;
5869 }
5870
5871 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5872 bool save_guys(const char *path)
5873 {
5874 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5875
5876 if(!f)
5877 {
5878 return false;
5879 }
5880
5881 /*
5882 int32_t id = ID_GUYS;
5883 if(!p_mputl(id,f))
5884 {
5885 return false;
5886 }
5887 */
5888
5889 zquestheader h;
5890 h.zelda_version = 0x250;
5891 h.build = 21;
5892
5893 if(writeguys(f, &h)==0)
5894 {
5895 pack_fclose(f);
5896 return true;
5897 }
5898
5899 pack_fclose(f);
5900 return false;
5901 }
5902
5903 bool load_guys(const char *path)
5904 {
5905 dword section_id;
5906 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5907
5908 if(!f)
5909 {
5910 return false;
5911 }
5912
5913 if(!p_mgetl(&section_id,f))
5914 {
5915 pack_fclose(f);
5916 return false;
5917 }
5918
5919 zquestheader h;
5920 h.zelda_version = 0x250;
5921 h.build = 21;
5922
5923 if(section_id==ID_GUYS)
5924 {
5925 if(readguys(f, &h)==0)
5926 {
5927 pack_fclose(f);
5928 return true;
5929 }
5930 }
5931
5932 pack_fclose(f);
5933 return false;
5934 }
5935
5936
5937 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5938 bool save_combo_alias(const char *path)
5939 {
5940 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5941
5942 if(!f)
5943 {
5944 return false;
5945 }
5946
5947 zquestheader h;
5948 h.zelda_version = 0x250;
5949 h.build = 21;
5950
5951 if(writecomboaliases(f, 0, 0)==0)
5952 {
5953 pack_fclose(f);
5954 return true;
5955 }
5956
5957 pack_fclose(f);
5958 return false;
5959 }
5960
5961 bool load_combo_alias(const char *path)
5962 {
5963 dword section_id;
5964 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5965
5966 if(!f)
5967 {
5968 return false;
5969 }
5970
5971 if(!p_mgetl(&section_id,f))
5972 {
5973 pack_fclose(f);
5974 return false;
5975 }
5976
5977 zquestheader h;
5978 h.zelda_version = 0x250;
5979 h.build = 21;
5980
5981 if(section_id==ID_COMBOALIASES)
5982 {
5983 if(readcomboaliases(f, &h, 0, 0)==0)
5984 {
5985 pack_fclose(f);
5986 return true;
5987 }
5988 }
5989
5990 pack_fclose(f);
5991 return false;
5992 }
5993
5994 bool load_zgp(const char *path)
5995 {
5996 dword section_id;
5997 dword section_version;
5998 dword section_cversion;
5999 // setPackfilePassword(NULL);
6000 PACKFILE *f=pack_fopen_password(path,F_READ,"");
6001
6002 if(!f)
6003 return false;
6004
6005 if(!p_mgetl(&section_id,f))
6006 {
6007 pack_fclose(f);
6008 return false;
6009 }
6010
6011 if(section_id!=ID_GRAPHICSPACK)
6012 {
6013 pack_fclose(f);
6014 return false;
6015 }
6016
6017 //section version info
6018 if(!p_igetw(&section_version,f))
6019 {
6020 return 2;
6021 }
6022
6023 if(!p_igetw(&section_cversion,f))
6024 {
6025 return 3;
6026 }
6027
6028 //tiles
6029 if(!p_mgetl(&section_id,f))
6030 {
6031 pack_fclose(f);
6032 return false;
6033 }
6034
6035 if(section_id==ID_TILES)
6036 {
6037 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6038 {
6039 pack_fclose(f);
6040 init_tiles(true, &header);
6041 return false;
6042 }
6043 }
6044 else
6045 {
6046 pack_fclose(f);
6047 return false;
6048 }
6049
6050 //combos
6051 if(!p_mgetl(&section_id,f))
6052 {
6053 pack_fclose(f);
6054 return false;
6055 }
6056
6057 if(section_id==ID_COMBOS)
6058 {
6059 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6060 {
6061 pack_fclose(f);
6062 // init_combos(true, &header);
6063 return false;
6064 }
6065 }
6066 else
6067 {
6068 pack_fclose(f);
6069 return false;
6070 }
6071
6072 //palettes
6073 if(!p_mgetl(&section_id,f))
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 if(section_id==ID_CSETS)
6080 {
6081 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086 }
6087 else
6088 {
6089 pack_fclose(f);
6090 return false;
6091 }
6092
6093 //items
6094 if(!p_mgetl(&section_id,f))
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 if(section_id==ID_ITEMS)
6101 {
6102 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6103 {
6104 pack_fclose(f);
6105 return false;
6106 }
6107 }
6108 else
6109 {
6110 pack_fclose(f);
6111 return false;
6112 }
6113
6114 //weapons
6115 if(!p_mgetl(&section_id,f))
6116 {
6117 pack_fclose(f);
6118 return false;
6119 }
6120
6121 if(section_id==ID_WEAPONS)
6122 {
6123 if(readweapons(f, &header)!=0)
6124 {
6125 pack_fclose(f);
6126 return false;
6127 }
6128 }
6129 else
6130 {
6131 pack_fclose(f);
6132 return false;
6133 }
6134
6135 //read the triforce pieces info and make sure it worked
6136 //really do this?
6137
6138 //read the game icons info and make sure it worked
6139 if(!p_mgetl(&section_id,f))
6140 {
6141 pack_fclose(f);
6142 return false;
6143 }
6144
6145 if(section_id==ID_ICONS)
6146 {
6147 if(readgameicons(f, &header, &QMisc)!=0)
6148 {
6149 pack_fclose(f);
6150 return false;
6151 }
6152 }
6153 else
6154 {
6155 pack_fclose(f);
6156 return false;
6157 }
6158
6159 //read the misc colors info and map styles info and make sure it worked
6160 if(!p_mgetl(&section_id,f))
6161 {
6162 pack_fclose(f);
6163 return false;
6164 }
6165
6166 if(section_id==ID_COLORS)
6167 {
6168 if(readmisccolors(f, &header, &QMisc)!=0)
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173 }
6174 else
6175 {
6176 pack_fclose(f);
6177 return false;
6178 }
6179
6180 //read the door combo sets and make sure it worked
6181 if(!p_mgetl(&section_id,f))
6182 {
6183 pack_fclose(f);
6184 return false;
6185 }
6186
6187 if(section_id==ID_DOORS)
6188 {
6189 if(readdoorcombosets(f, &header)!=0)
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194 }
6195 else
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200
6201 //read the template screens and make sure it worked
6202 //really do this?
6203
6204 //yay! it worked! close the file and say everything was ok.
6205 loadlvlpal(Color);
6206 setup_combo_animations();
6207 setup_combo_animations2();
6208 pack_fclose(f);
6209 return true;
6210 }
6211
6212 bool save_zgp(const char *path)
6213 {
6214 // jwin_alert("Error","This feature not yet implemented.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6215 // return false;
6216 reset_combo_animations();
6217 reset_combo_animations2();
6218
6219 //open the file
6220 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6221
6222 if(!f)
6223 return false;
6224
6225 dword section_id=ID_GRAPHICSPACK;
6226 dword section_version=V_GRAPHICSPACK;
6227 dword section_cversion=CV_GRAPHICSPACK;
6228
6229 //section id
6230 if(!p_mputl(section_id,f))
6231 {
6232 return 1;
6233 }
6234
6235 //section version info
6236 if(!p_iputw(section_version,f))
6237 {
6238 return 2;
6239 }
6240
6241 if(!p_iputw(section_cversion,f))
6242 {
6243 return 3;
6244 }
6245
6246 //tiles
6247 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6248 {
6249 pack_fclose(f);
6250 return false;
6251 }
6252
6253 //combos
6254 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6255 {
6256 pack_fclose(f);
6257 return false;
6258 }
6259
6260 //palettes
6261 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6262 {
6263 pack_fclose(f);
6264 return false;
6265 }
6266
6267 //items
6268 if(writeitems(f, &header)!=0)
6269 {
6270 pack_fclose(f);
6271 return false;
6272 }
6273
6274 //weapons
6275 if(writeweapons(f, &header)!=0)
6276 {
6277 pack_fclose(f);
6278 return false;
6279 }
6280
6281 //write the triforce pieces info and make sure it worked
6282 //really do this?
6283
6284 //write the game icons info and make sure it worked
6285 if(writegameicons(f, &header)!=0)
6286 {
6287 pack_fclose(f);
6288 return false;
6289 }
6290
6291 //write the misc colors info and map styles info and make sure it worked
6292 if(writemisccolors(f, &header)!=0)
6293 {
6294 pack_fclose(f);
6295 return false;
6296 }
6297
6298 //write the door combo sets and make sure it worked
6299 if(writedoorcombosets(f, &header)!=0)
6300 {
6301 pack_fclose(f);
6302 return false;
6303 }
6304
6305 //write the template screens and make sure it worked
6306 //really do this?
6307
6308 pack_fclose(f);
6309 return true;
6310 }
6311
6312 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6313 {
6314 //open the file
6315 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6316
6317 if(!f)
6318 return false;
6319
6320 dword section_id=ID_SUBSCREEN;
6321 dword s_version=V_SUBSCREEN;
6322 dword s_cversion=CV_SUBSCREEN;
6323
6324 if(!p_mputl(section_id,f))
6325 {
6326 pack_fclose(f);
6327 return false;
6328 }
6329
6330 if(!p_iputw(s_version,f))
6331 {
6332 pack_fclose(f);
6333 return false;
6334 }
6335
6336 if(!p_iputw(s_cversion,f))
6337 {
6338 pack_fclose(f);
6339 return false;
6340 }
6341
6342 if(savefrom.write(f))
6343 {
6344 pack_fclose(f);
6345 return false;
6346 }
6347
6348 pack_fclose(f);
6349 return true;
6350 }
6351
6352 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6353 {
6354 //open the file
6355 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6356
6357 if(!f)
6358 return false;
6359
6360 dword section_id;
6361 dword s_version;
6362 dword s_cversion;
6363
6364 if(!p_mgetl(&section_id,f))
6365 {
6366 pack_fclose(f);
6367 return false;
6368 }
6369
6370 if(section_id!=ID_SUBSCREEN)
6371 {
6372 pack_fclose(f);
6373 return false;
6374 }
6375
6376 if(!p_igetw(&s_version,f))
6377 {
6378 pack_fclose(f);
6379 return false;
6380 }
6381
6382 if(!p_igetw(&s_cversion,f))
6383 {
6384 pack_fclose(f);
6385 return false;
6386 }
6387
6388 if(s_version < 8)
6389 {
6390 subscreen_group g;
6391 memset(&g,0,sizeof(subscreen_group));
6392 if(read_one_old_subscreen(f,&g,s_version)!=0)
6393 {
6394 pack_fclose(f);
6395 return false;
6396 }
6397 if(g.ss_type != loadto.sub_type)
6398 {
6399 pack_fclose(f);
6400 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6401 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6402 return false;
6403 }
6404 loadto.clear();
6405 if(g.objects[0].type != ssoNULL)
6406 loadto.load_old(g);
6407 }
6408 else
6409 {
6410 ZCSubscreen tmp = ZCSubscreen();
6411 if (tmp.read(f, s_version))
6412 {
6413 pack_fclose(f);
6414 return false;
6415 }
6416 if(tmp.sub_type != loadto.sub_type)
6417 {
6418 pack_fclose(f);
6419 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6420 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6421 return false;
6422 }
6423 loadto.clear();
6424 loadto = tmp;
6425 }
6426
6427 pack_fclose(f);
6428 return true;
6429 }
6430
6431 bool setMapCount2(int32_t c)
6432 {
6433 int32_t oldmapcount=map_count;
6434 int32_t currmap=Map.getCurrMap();
6435
6436 bound(c,1,MAXMAPS);
6437 map_count=c;
6438
6439 try
6440 {
6441 TheMaps.resize(c*MAPSCRS);
6442 Map.force_refr_pointer();
6443 map_autolayers.resize(c*6);
6444 }
6445 catch(...)
6446 {
6447 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6448 return false;
6449 }
6450
6451 bound(currmap,0,c-1);
6452 if(map_count>oldmapcount)
6453 {
6454 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6455 {
6456 Map.setCurrMap(mc);
6457
6458 for(int32_t ms=0; ms<MAPSCRS; ms++)
6459 {
6460 Map.clearscr(ms);
6461 }
6462 }
6463 Map.setCurrMap(currmap);
6464 }
6465 else
6466 {
6467 Map.setCurrMap(currmap);
6468 if(!layers_valid(Map.CurrScr()))
6469 fix_layers(Map.CurrScr(), false);
6470
6471 for(int32_t i=0; i<MAXDMAPS; i++)
6472 {
6473 if(DMaps[i].map>=map_count)
6474 {
6475 DMaps[i].map=map_count-1;
6476 }
6477 }
6478 }
6479
6480 return true;
6481 }
6482
6483 extern BITMAP *bmap;
6484
6485 static bool loading_file_new = false;
6486 1 int32_t init_quest()
6487 {
6488 char qstdat_string[2048];
6489 1 strcpy(qstdat_string, "modules/classic/default.qst");
6490
6491 char buf[2048];
6492
6493 1 loading_file_new = true;
6494 1 load_quest(qstdat_string);
6495 1 loading_file_new = false;
6496
6497 1 sprintf(buf,"ZC Editor - Untitled Quest");
6498 1 set_window_title(buf);
6499 1 zinit.last_map = 0;
6500 1 zinit.last_screen = 0;
6501
6502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6503 {
6504 destroy_bitmap(bmap);
6505 bmap=NULL;
6506 }
6507
6508 1 return 0;
6509 }
6510
6511 void set_questpwd(std::string_view pwd, bool use_keyfile)
6512 {
6513 header.use_keyfile=use_keyfile;
6514
6515 // string_view actually has some quirks that make it less than ideal here.
6516 // It'd probably be best to replace it, but this works for now.
6517 memset(header.password, 0, 256);
6518 strcpy(header.password, pwd.data());
6519 header.dirty_password=true;
6520
6521 cvs_MD5Context ctx;
6522 cvs_MD5Init(&ctx);
6523 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6524 cvs_MD5Final(header.pwd_hash, &ctx);
6525 }
6526
6527
6528 bool is_null_pwd_hash(uint8_t *pwd_hash)
6529 {
6530 cvs_MD5Context ctx;
6531 uint8_t md5sum[16];
6532 char pwd[2]="";
6533
6534 cvs_MD5Init(&ctx);
6535 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6536 cvs_MD5Final(md5sum, &ctx);
6537
6538 return (memcmp(md5sum,pwd_hash,16)==0);
6539 }
6540
6541 static DIALOG pwd_dlg[] =
6542 {
6543 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6544 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6545 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6546 // 2 (filename)
6547 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6548 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6549 // 4 (challenge hash)
6550 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6551 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6552 // 6 (password)
6553 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6554 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6555 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6556 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6557 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6558 };
6559
6560 int32_t reverse_string(char* str)
6561 {
6562
6563 if(NULL==str)
6564 {
6565 return -1; //no string
6566 }
6567
6568 int32_t l=(int32_t)strlen(str)-1; //get the string length
6569
6570 if(1==l)
6571 {
6572 return 1;
6573 }
6574
6575 char c;
6576
6577 for(int32_t x=0; x < l; x++,l--)
6578 {
6579 c = str[x];
6580 str[x] = str[l];
6581 str[l] = c;
6582 }
6583
6584 return 0;
6585 }
6586
6587 #ifdef __GNUC__
6588 #pragma GCC diagnostic push
6589 #pragma GCC diagnostic ignored "-Wunreachable-code"
6590 #endif
6591
6592 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6593 {
6594 #ifdef __EMSCRIPTEN__
6595 return 1;
6596 #endif
6597
6598 //Protection against compiling a release version with password protection off.
6599 static bool passguard = false;
6600
6601 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6602 #define MUST_HAVE_PASSWORD
6603 9 passguard = true;
6604 #endif
6605
6606 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6607 #if (defined _MSC_VER || defined _NPASS)
6608 return 1;
6609 #endif
6610 #endif
6611
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(devpwd()) return 1;
6612
6613 char hash_string[33];
6614
6615 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6616 {
6617 return 1;
6618 }
6619
6620 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6621 return true;
6622
6623 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6624 pwd_dlg[2].dp=get_filename(filename);
6625 cvs_MD5Context ctx;
6626 uint8_t md5sum[16]={0};
6627 char response[33]="";
6628 char prompt[256]="";
6629
6630 memcpy(md5sum, hdr->pwd_hash, 16);
6631
6632 for(int32_t i=0; i<300; ++i)
6633 {
6634 for(int32_t j=0; j<16; ++j)
6635 {
6636 sprintf(response+j*2, "%02x", md5sum[j]);
6637 }
6638
6639 if(i&1)
6640 {
6641 reverse_string(response);
6642 }
6643
6644 if(i==149)
6645 {
6646 strcpy(hash_string, response);
6647 }
6648
6649 cvs_MD5Init(&ctx);
6650 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6651 cvs_MD5Final(md5sum, &ctx);
6652 }
6653
6654 pwd_dlg[4].dp=hash_string;
6655
6656 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6657 {
6658 sprintf(prompt,"%s",response);
6659 }
6660
6661 pwd_dlg[6].dp=prompt;
6662
6663 large_dialog(pwd_dlg);
6664
6665 int32_t cancel = do_zqdialog(pwd_dlg,6);
6666
6667 if(cancel == 8)
6668 return 2;
6669
6670 bool ret=check_questpwd(hdr, prompt);
6671
6672 if(!ret)
6673 {
6674 ret=(strcmp(response,prompt)==0);
6675 }
6676 return ret ? 1 : 0;
6677 9 }
6678
6679 void set_rules(byte* newrules);
6680 8 void popup_bugfix_dlg(const char* cfg)
6681 {
6682 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6683
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6684 {
6685
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6686
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6687 "\nWould you like to apply them?"
6688 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6689 8 [&](bool ret,bool dsa)
6690 {
6691 if(ret)
6692 {
6693 applyRuleTemplate(ruletemplateFixCompat);
6694 }
6695 if(dsa)
6696 {
6697 zc_set_config("zquest",cfg,1);
6698 }
6699 },
6700
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6701 0,false, //timeout - none
6702 true //"Don't show this again"
6703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6704 8 }
6705 8 }
6706
6707 #ifdef __GNUC__
6708 #pragma GCC diagnostic pop
6709 #endif
6710
6711 // wrapper to reinitialize everything on an error
6712 9 int32_t load_quest(const char *filename, bool show_progress)
6713 {
6714 char buf[2048];
6715 // if(encrypted)
6716 // setPackfilePassword(datapwd);
6717 byte skip_flags[4];
6718
6719
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6720 {
6721 36 skip_flags[i]=0;
6722 36 }
6723
2/2
✓ Branch 0 taken 6210 times.
✓ Branch 1 taken 9 times.
6219 for(int32_t i=0; i<qr_MAX; i++)
6724 6210 set_qr(i,0);
6725 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6726 // setPackfilePassword(NULL);
6727
6728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6729 {
6730 init_quest();
6731 }
6732 else
6733 {
6734 9 int32_t accessret = quest_access(filename, &header);
6735
6736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6737 {
6738 init_quest();
6739
6740 if(accessret == 0)
6741 ret=qe_pwd;
6742 else
6743 ret=qe_cancel;
6744 }
6745 else
6746 {
6747 9 Map.clear();
6748 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6749 9 Map.setCurrScr(zinit.last_screen);
6750 extern int32_t current_mappage;
6751 9 current_mappage = 0;
6752 9 bool found_default = false;
6753
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6754 {
6755 65 auto &pg = map_page[q];
6756
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6757 {
6758 2 current_mappage = q;
6759 2 break;
6760 }
6761
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6762 56 continue;
6763 else
6764 {
6765 7 current_mappage = q;
6766 7 found_default = true;
6767 }
6768 7 }
6769 9 refresh(rALL);
6770 9 refresh_pal();
6771 9 set_rules(quest_rules);
6772 9 saved = true;
6773
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6774 8 popup_bugfix_dlg("dsa_compatrule");
6775
6776
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6777 {
6778 destroy_bitmap(bmap);
6779 bmap=NULL;
6780 }
6781
6782
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6783 {
6784 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6785 1 set_window_title(buf);
6786 1 }
6787 }
6788 }
6789
6790 9 Map.ClearCommandHistory();
6791
6792 9 return ret;
6793 }
6794
6795 int32_t load_tileset(const char *filename, dword tsetflags)
6796 {
6797 char buf[2048];
6798 byte skip_flags[4];
6799
6800 for(int32_t i=0; i<4; ++i)
6801 skip_flags[i]=0;
6802 for(int32_t i=0; i<qr_MAX; i++)
6803 set_qr(i,0);
6804 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6805
6806 if(ret!=qe_OK)
6807 init_quest();
6808 else
6809 {
6810 int32_t accessret = quest_access(filename, &header);
6811
6812 if(accessret != 1)
6813 {
6814 init_quest();
6815
6816 if(accessret == 0)
6817 ret=qe_pwd;
6818 else
6819 ret=qe_cancel;
6820 }
6821 else
6822 {
6823 Map.clear();
6824 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6825 Map.setCurrScr(zinit.last_screen);
6826 extern int32_t current_mappage;
6827 current_mappage = 0;
6828 bool found_default = false;
6829 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6830 {
6831 auto &pg = map_page[q];
6832 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6833 {
6834 current_mappage = q;
6835 break;
6836 }
6837 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6838 continue;
6839 else
6840 {
6841 current_mappage = q;
6842 found_default = true;
6843 }
6844 }
6845 refresh(rALL);
6846 refresh_pal();
6847 set_rules(quest_rules);
6848 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6849 popup_bugfix_dlg("dsa_compatrule");
6850
6851 if(bmap != NULL)
6852 {
6853 destroy_bitmap(bmap);
6854 bmap=NULL;
6855 }
6856
6857 set_window_title("ZC Editor - Untitled Quest");
6858 first_save = saved = false;
6859 memset(filepath,0,255);
6860 memset(temppath,0,255);
6861 }
6862 }
6863
6864 Map.ClearCommandHistory();
6865
6866 return ret;
6867 }
6868
6869 60 bool write_midi(MIDI *m,PACKFILE *f)
6870 {
6871 int32_t c;
6872
6873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6874
6875
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6876 {
6877
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6878
6879
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6880 {
6881
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6882 return false;
6883 492 }
6884 1920 }
6885
6886 60 return true;
6887 60 }
6888
6889 bool write_music(int32_t format, MIDI* m, PACKFILE *f)
6890 {
6891 // format - data format (midi, nsf, ...)
6892 // m - pointer to data.
6893
6894 int32_t c;
6895
6896 switch(format)
6897 {
6898 case MFORMAT_MIDI:
6899
6900 if(!p_mputw(m->divisions,f)) return false;
6901
6902 for(c=0; c<MIDI_TRACKS; c++)
6903 {
6904 if(!p_mputl(m->track[c].len,f)) return false;
6905
6906 if(m->track[c].len > 0)
6907 {
6908 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6909 return false;
6910 }
6911 }
6912
6913 break;
6914
6915 case MFORMAT_NSF:
6916
6917 break;
6918
6919 default:
6920 return false;
6921 break;
6922 }
6923
6924 return true;
6925 }
6926
6927 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6928 {
6929 6 dword section_id=ID_HEADER;
6930 6 dword section_version=V_HEADER;
6931 6 dword section_cversion=CV_HEADER;
6932 6 dword section_size=0;
6933
6934 //file header string
6935
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6936 {
6937 new_return(1);
6938 }
6939
6940 //section id
6941
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6942 {
6943 new_return(2);
6944 }
6945
6946 //section version info
6947
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6948 {
6949 new_return(3);
6950 }
6951
6952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6953 {
6954 new_return(4);
6955 }
6956
6957
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6958 {
6959 12 fake_pack_writing=(writecycle==0);
6960
6961 //section size
6962
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6963 {
6964 new_return(5);
6965 }
6966
6967 12 writesize=0;
6968
6969 //finally... section data
6970
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6971 {
6972 new_return(6);
6973 }
6974
6975
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6976 {
6977 new_return(7);
6978 }
6979
6980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6981 {
6982 new_return(8);
6983 }
6984
6985
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6986 {
6987 new_return(10);
6988 }
6989
6990
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6991 {
6992 new_return(11);
6993 }
6994
6995
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6996 {
6997 new_return(12);
6998 }
6999
7000
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
7001 {
7002 new_return(13);
7003 }
7004
7005
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
7006 {
7007 new_return(14);
7008 }
7009
7010
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
7011 {
7012 new_return(15);
7013 }
7014
7015
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
7016 {
7017 new_return(16);
7018 }
7019
7020
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
7021 {
7022 new_return(17);
7023 }
7024
7025
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
7026 {
7027 new_return(19);
7028 }
7029
7030
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
7031 //this is for map count, it seems. -Z
7032 {
7033 new_return(20);
7034 }
7035
7036 12 auto version = getVersion();
7037
7038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
7039 {
7040 new_return(21);
7041 }
7042
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
7043 {
7044 new_return(22);
7045 }
7046
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
7047 {
7048 new_return(23);
7049 }
7050 // Fourth component is deprecated.
7051
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7052 {
7053 new_return(24);
7054 }
7055
7056 // Numerous prerelease stages is deprecated.
7057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7058 {
7059 new_return(25);
7060 }
7061
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7062 {
7063 new_return(26);
7064 }
7065
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7066 {
7067 new_return(27);
7068 }
7069
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7070 {
7071 new_return(28);
7072 }
7073
7074
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7075 {
7076 new_return(29);
7077 }
7078
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7079 {
7080 new_return(30);
7081 }
7082
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7083 {
7084 new_return(31);
7085 }
7086
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7087 {
7088 new_return(32);
7089 }
7090
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7091 {
7092 new_return(33);
7093 }
7094
7095
7096
7097 char tempsig[256];
7098 12 memset(tempsig, 0, 256);
7099 12 strcpy(tempsig, DEV_SIGNOFF);
7100
7101
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7102 {
7103 new_return(34);
7104 }
7105
7106 char tempcompilersig[256];
7107 12 memset(tempcompilersig, 0, 256);
7108 12 strcpy(tempcompilersig, COMPILER_NAME);
7109
7110
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7111 {
7112 new_return(35);
7113 }
7114
7115 char tempcompilerversion[256];
7116 12 memset(tempcompilerversion, 0, 256);
7117 #ifdef _MSC_VER
7118 zc_itoa(_MSC_VER,tempcompilerversion,10);
7119 #else
7120 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7121 #endif
7122
7123
7124
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7125 {
7126 new_return(36);
7127 }
7128
7129
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7130 {
7131 new_return(37);
7132 }
7133
7134
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7135 {
7136 new_return(38);
7137 }
7138 #ifdef _MSC_VER
7139 if(!p_iputl((_MSC_VER / 100),f))
7140 {
7141 new_return(39);
7142 }
7143 #else
7144
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7145 {
7146 new_return(39);
7147 }
7148 #endif
7149
7150
7151
7152 #ifdef _MSC_VER
7153 if(!p_iputl((_MSC_VER % 100),f))
7154 {
7155 new_return(41);
7156 }
7157 #else
7158
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7159 {
7160 new_return(41);
7161 }
7162 #endif
7163
7164 #ifdef _MSC_VER
7165 # if _MSC_VER >= 1400
7166 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7167 {
7168 new_return(40);
7169 }
7170 # else
7171 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7172 {
7173 new_return(40);
7174 }
7175 #endif
7176 #else
7177
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7178 {
7179 new_return(40);
7180 }
7181 #endif
7182
7183 #ifdef _MSC_VER
7184 if(!p_iputl((_MSC_BUILD),f))
7185 {
7186 new_return(42);
7187 }
7188 #else
7189
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7190 {
7191 new_return(42);
7192 }
7193 #endif
7194
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7195 {
7196 new_return(43);
7197 }
7198
7199 char tempmodulename[1024];
7200 12 memset(tempmodulename, 0, 1024);
7201 12 strcpy(tempmodulename, moduledata.module_name);
7202
7203
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7204 {
7205 new_return(44);
7206 }
7207
7208 char tempdate[256];
7209 12 memset(tempdate, 0, 256);
7210 12 strcpy(tempdate, __DATE__);
7211
7212
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7213 {
7214 new_return(45);
7215 }
7216 char temptime[256];
7217 12 memset(temptime, 0, 256);
7218 12 strcpy(temptime, __TIME__);
7219
7220
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7221 {
7222 new_return(46);
7223 }
7224
7225
7226 char temptimezone[6];
7227 12 memset(temptimezone, 0, 6);
7228 12 strcpy(temptimezone, __TIMEZONE__);
7229
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7230 {
7231 new_return(47);
7232 }
7233
7234
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7235 {
7236 new_return(48);
7237 }
7238
7239
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7240 {
7241 new_return(49);
7242 }
7243
7244
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7245 {
7246 new_return(50);
7247 }
7248
7249
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7250 {
7251 6 section_size=writesize;
7252 6 }
7253 12 }
7254
7255
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7256 {
7257 char ebuf[80];
7258 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7259 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7260 }
7261
7262 6 new_return(0);
7263 }
7264
7265 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7266 {
7267 //these are here to bypass compiler warnings about unused arguments
7268 6 Header=Header;
7269
7270 6 dword section_id=ID_RULES;
7271 6 dword section_version=V_RULES;
7272 6 dword section_cversion=CV_RULES;
7273 6 dword section_size=0;
7274
7275 //section id
7276
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7277 {
7278 new_return(1);
7279 }
7280
7281 //section version info
7282
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7283 {
7284 new_return(2);
7285 }
7286
7287
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7288 {
7289 new_return(3);
7290 }
7291
7292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7293 {
7294 new_return(6);
7295 }
7296
7297
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7298 {
7299 12 fake_pack_writing=(writecycle==0);
7300
7301 //section size
7302
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7303 {
7304 new_return(4);
7305 }
7306
7307 12 writesize=0;
7308
7309 //finally... section data
7310
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7311 {
7312 new_return(5);
7313 }
7314
7315
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7316 {
7317 6 section_size=writesize;
7318 6 }
7319 12 }
7320
7321
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7322 {
7323 char ebuf[80];
7324 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7325 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7326 }
7327
7328 6 new_return(0);
7329 }
7330
7331
7332 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7333 {
7334 //these are here to bypass compiler warnings about unused arguments
7335 6 Header=Header;
7336
7337 6 dword section_id=ID_DOORS;
7338 6 dword section_version=V_DOORS;
7339 6 dword section_cversion=CV_DOORS;
7340 6 dword section_size=0;
7341
7342 //section id
7343
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7344 {
7345 new_return(1);
7346 }
7347
7348 //section version info
7349
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7350 {
7351 new_return(2);
7352 }
7353
7354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7355 {
7356 new_return(3);
7357 }
7358
7359
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7360 {
7361 12 fake_pack_writing=(writecycle==0);
7362
7363 //section size
7364
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7365 {
7366 new_return(4);
7367 }
7368
7369 12 writesize=0;
7370
7371 //finally... section data
7372
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7373 {
7374 new_return(5);
7375 }
7376
7377
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7378 {
7379 //name
7380
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7381 {
7382 new_return(6);
7383 }
7384
7385 //up door
7386
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7387 {
7388
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7389 {
7390
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7391 {
7392 new_return(7);
7393 }
7394 5904 }
7395 1476 }
7396
7397
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7398 {
7399
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7400 {
7401
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7402 {
7403 new_return(8);
7404 }
7405 5904 }
7406 1476 }
7407
7408 //down door
7409
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7410 {
7411
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7412 {
7413
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7414 {
7415 new_return(9);
7416 }
7417 5904 }
7418 1476 }
7419
7420
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7421 {
7422
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7423 {
7424
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7425 {
7426 new_return(10);
7427 }
7428 5904 }
7429 1476 }
7430
7431
7432 //left door
7433
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7434 {
7435
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7436 {
7437
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7438
7439 {
7440 new_return(11);
7441 }
7442 8856 }
7443 1476 }
7444
7445
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7446 {
7447
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7448 {
7449
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7450 {
7451 new_return(12);
7452 }
7453 8856 }
7454 1476 }
7455
7456 //right door
7457
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7458 {
7459
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7460 {
7461
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7462 {
7463 new_return(13);
7464 }
7465 8856 }
7466 1476 }
7467
7468
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7469 {
7470
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7471 {
7472
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7473 {
7474 new_return(14);
7475 }
7476 8856 }
7477 1476 }
7478
7479
7480 //up bomb rubble
7481
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7482 {
7483
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7484 {
7485 new_return(15);
7486 }
7487 328 }
7488
7489
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7490 {
7491
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7492 {
7493 new_return(16);
7494 }
7495 328 }
7496
7497 //down bomb rubble
7498
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7499 {
7500
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7501 {
7502 new_return(17);
7503 }
7504 328 }
7505
7506
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7507 {
7508
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7509 {
7510 new_return(18);
7511 }
7512 328 }
7513
7514 //left bomb rubble
7515
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7516 {
7517
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7518 {
7519 new_return(19);
7520 }
7521 492 }
7522
7523
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7524 {
7525
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7526 {
7527 new_return(20);
7528 }
7529 492 }
7530
7531 //right bomb rubble
7532
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7533 {
7534
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7535 {
7536 new_return(21);
7537 }
7538 492 }
7539
7540
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7541 {
7542
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7543 {
7544 new_return(22);
7545 }
7546 492 }
7547
7548 //walkthrough stuff
7549
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7550 {
7551
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7552 {
7553 new_return(23);
7554 }
7555 656 }
7556
7557
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7558 {
7559
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7560 {
7561 new_return(24);
7562 }
7563 656 }
7564
7565 //flags
7566
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7567 {
7568
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7569 {
7570 new_return(25);
7571 }
7572 328 }
7573 164 }
7574
7575
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7576 {
7577 6 section_size=writesize;
7578 6 }
7579 12 }
7580
7581
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7582 {
7583 char ebuf[80];
7584 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7585 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7586 }
7587
7588 6 new_return(0);
7589 }
7590
7591 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7592 {
7593 //these are here to bypass compiler warnings about unused arguments
7594 6 version=version;
7595 6 build=build;
7596
7597 6 word dmap_count=count_dmaps();
7598 6 dword section_id=ID_DMAPS;
7599 6 dword section_version=V_DMAPS;
7600 6 dword section_cversion=CV_DMAPS;
7601 6 dword section_size=0;
7602
7603 //section id
7604
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7605 {
7606 new_return(1);
7607 }
7608
7609 //section version info
7610
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7611 {
7612 new_return(2);
7613 }
7614
7615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7616 {
7617 new_return(3);
7618 }
7619
7620
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7621 {
7622 12 fake_pack_writing=(writecycle==0);
7623
7624 //section size
7625
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7626 {
7627 new_return(4);
7628 }
7629
7630 12 writesize=0;
7631
7632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7634
7635 //finally... section data
7636
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7637 {
7638 new_return(5);
7639 }
7640
7641
7642
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7643 {
7644 6144 DMaps[i].validate_subscreens();
7645
7646
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7647 {
7648 new_return(6);
7649 }
7650
7651
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7652 {
7653 new_return(7);
7654 }
7655
7656
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7657 {
7658 new_return(8);
7659 }
7660
7661
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7662 {
7663 new_return(9);
7664 }
7665
7666
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7667 {
7668 new_return(10);
7669 }
7670
7671
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7672 {
7673 new_return(11);
7674 }
7675
7676
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7677 {
7678 new_return(12);
7679 }
7680
7681
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7682 {
7683 new_return(13);
7684 }
7685
7686
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7687 {
7688
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7689 {
7690 new_return(14);
7691 }
7692 49152 }
7693
7694
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7695 {
7696 new_return(15);
7697 }
7698
7699
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7700 {
7701 new_return(16);
7702 }
7703
7704
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7705 {
7706 new_return(17);
7707 }
7708
7709
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7710 {
7711 new_return(18);
7712 }
7713
7714
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7715 {
7716 new_return(19);
7717 }
7718
7719
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7720 {
7721 new_return(20);
7722 }
7723
7724
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7725 {
7726 new_return(21);
7727 }
7728
7729
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7730 {
7731 new_return(22);
7732 }
7733
7734
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7735 {
7736 new_return(23);
7737 }
7738
7739
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7740 {
7741 new_return(24);
7742 }
7743
7744
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7745 {
7746 new_return(25);
7747 }
7748
7749
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7750 {
7751 new_return(26);
7752 }
7753
7754
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7755 {
7756 new_return(25);
7757 }
7758
7759
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7760 {
7761 new_return(26);
7762 }
7763
7764
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7765 {
7766 new_return(27);
7767 }
7768
7769 byte disabled[32];
7770 6144 memset(disabled,0,32);
7771
7772
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7773 {
7774
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7775 {
7776 disabled[j/8] |= (1 << (j%8));
7777 }
7778 1572864 }
7779
7780
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7781 {
7782 new_return(28);
7783 }
7784
7785
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7786 {
7787 new_return(29);
7788 }
7789
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7790 {
7791 new_return(30);
7792 }
7793
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7794 {
7795 new_return(31);
7796 }
7797
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7798 {
7799
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7800 {
7801 new_return(32);
7802 }
7803
7804 49152 }
7805
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7806 {
7807
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7808 {
7809
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7810 {
7811 new_return(33);
7812 }
7813 3194880 }
7814 49152 }
7815
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7816 {
7817 new_return(34);
7818 }
7819
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7820 {
7821 new_return(35);
7822 }
7823
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7824 {
7825
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7826 {
7827 new_return(36);
7828 }
7829 49152 }
7830
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7831 {
7832
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7833 {
7834
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7835 {
7836 new_return(37);
7837 }
7838 3194880 }
7839 49152 }
7840
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7841 {
7842 new_return(38);
7843 }
7844
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7845 {
7846
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7847 {
7848 new_return(39);
7849 }
7850 49152 }
7851
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7852 {
7853
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7854 {
7855
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7856 {
7857 new_return(40);
7858 }
7859 3194880 }
7860 49152 }
7861
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7862 {
7863 new_return(41);
7864 }
7865
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7866 {
7867 new_return(42);
7868 }
7869
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7870 {
7871 new_return(43);
7872 }
7873
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7874 {
7875 new_return(44);
7876 }
7877
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7878 {
7879 new_return(45);
7880 }
7881
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7882 new_return(46);
7883
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7884 new_return(47);
7885
7886 // Reserved for z3.
7887
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7888 {
7889
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7890 {
7891
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7892 {
7893 new_return(48);
7894 }
7895 393216 }
7896 49152 }
7897 6144 }
7898
7899
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7900 {
7901 6 section_size=writesize;
7902 6 }
7903 12 }
7904
7905
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7906 {
7907 char ebuf[80];
7908 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7909 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7910 }
7911
7912 6 new_return(0);
7913 }
7914
7915 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7916 {
7917 //these are here to bypass compiler warnings about unused arguments
7918 6 Header=Header;
7919
7920 6 dword section_id=ID_COLORS;
7921 6 dword section_version=V_COLORS;
7922 6 dword section_cversion=CV_COLORS;
7923 6 dword section_size = 0;
7924
7925 //section id
7926
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7927 {
7928 new_return(1);
7929 }
7930
7931
7932 //section version info
7933
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7934 {
7935 new_return(2);
7936 }
7937
7938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7939 {
7940 new_return(3);
7941 }
7942
7943
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7944 {
7945 12 fake_pack_writing=(writecycle==0);
7946
7947 //section size
7948
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7949 {
7950 new_return(4);
7951 }
7952
7953 12 writesize=0;
7954
7955
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7956 {
7957 new_return(5);
7958 }
7959
7960
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7961 {
7962 new_return(6);
7963 }
7964
7965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7966 {
7967 new_return(7);
7968 }
7969
7970
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7971 {
7972 new_return(8);
7973 }
7974
7975
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7976 {
7977 new_return(9);
7978 }
7979
7980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7981 {
7982 new_return(10);
7983 }
7984
7985
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7986 {
7987 new_return(11);
7988 }
7989
7990
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7991 {
7992 new_return(12);
7993 }
7994
7995
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7996 {
7997 new_return(13);
7998 }
7999
8000
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
8001 {
8002 new_return(14);
8003 }
8004
8005
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
8006 {
8007 new_return(15);
8008 }
8009
8010
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
8011 {
8012 new_return(16);
8013 }
8014
8015
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
8016 {
8017 new_return(17);
8018 }
8019
8020
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
8021 {
8022 new_return(18);
8023 }
8024
8025
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
8026 {
8027 new_return(19);
8028 }
8029
8030
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
8031 {
8032 new_return(20);
8033 }
8034
8035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
8036 {
8037 new_return(21);
8038 }
8039
8040
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
8041 {
8042 new_return(22);
8043 }
8044
8045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
8046 {
8047 new_return(23);
8048 }
8049
8050
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8051 {
8052 new_return(24);
8053 }
8054
8055
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8056 {
8057 new_return(31);
8058 }
8059
8060
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8061 {
8062 new_return(32);
8063 }
8064
8065
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8066 {
8067 new_return(33);
8068 }
8069
8070
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8071 {
8072 new_return(34);
8073 }
8074
8075
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8076 {
8077 new_return(35);
8078 }
8079
8080
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8081 {
8082 new_return(36);
8083 }
8084
8085
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8086 {
8087 new_return(37);
8088 }
8089
8090
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8091 {
8092 new_return(38);
8093 }
8094
8095
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8096 {
8097 new_return(39);
8098 }
8099
8100
8101
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8102 {
8103 6 section_size=writesize;
8104 6 }
8105 12 }
8106
8107
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8108 {
8109 char ebuf[80];
8110 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8111 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8112 }
8113
8114 6 new_return(0);
8115 }
8116
8117 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8118 {
8119 //these are here to bypass compiler warnings about unused arguments
8120 6 Header=Header;
8121
8122 6 dword section_id=ID_ICONS;
8123 6 dword section_version=V_ICONS;
8124 6 dword section_cversion=CV_ICONS;
8125 6 dword section_size = 0;
8126
8127 //section id
8128
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8129 {
8130 new_return(1);
8131 }
8132
8133 //section version info
8134
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8135 {
8136 new_return(2);
8137 }
8138
8139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8140 {
8141 new_return(3);
8142 }
8143
8144
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8145 {
8146 12 fake_pack_writing=(writecycle==0);
8147
8148 //section size
8149
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8150 {
8151 new_return(4);
8152 }
8153
8154 12 writesize=0;
8155
8156
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8157 {
8158
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8159 {
8160 new_return(5);
8161 }
8162 48 }
8163
8164
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8165 {
8166 6 section_size=writesize;
8167 6 }
8168 12 }
8169
8170
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8171 {
8172 char ebuf[80];
8173 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8174 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8175 }
8176
8177 6 new_return(0);
8178 }
8179
8180 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8181 {
8182 //these are here to bypass compiler warnings about unused arguments
8183 6 Header=Header;
8184
8185 6 dword section_id=ID_MISC;
8186 6 dword section_version=V_MISC;
8187 6 dword section_cversion=CV_MISC;
8188 6 word shops=count_shops(&QMisc);
8189 6 word infos=count_infos(&QMisc);
8190 6 word warprings=count_warprings(&QMisc);
8191 6 word triforces=8;
8192 6 dword section_size = 0;
8193
8194 //section id
8195
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8196 {
8197 new_return(1);
8198 }
8199
8200
8201 //section version info
8202
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8203 {
8204 new_return(2);
8205 }
8206
8207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8208 {
8209 new_return(3);
8210 }
8211
8212
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8213 {
8214 12 fake_pack_writing=(writecycle==0);
8215
8216 //section size
8217
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8218 {
8219 new_return(4);
8220 }
8221
8222 12 writesize=0;
8223
8224 //shops
8225
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8226 {
8227 new_return(5);
8228 }
8229
8230
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8231 {
8232
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8233 {
8234 new_return(6);
8235 }
8236
8237
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8238 {
8239
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8240 {
8241 new_return(7);
8242 }
8243 384 }
8244
8245
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8246 {
8247
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8248 {
8249 new_return(8);
8250 }
8251 384 }
8252
8253
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8254 {
8255
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8256 {
8257 new_return(9);
8258 }
8259 384 }
8260 128 }
8261
8262 //infos
8263
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8264 {
8265 new_return(10);
8266 }
8267
8268
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8269 {
8270
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8271 {
8272 new_return(11);
8273 }
8274
8275
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8276 {
8277
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8278 {
8279 new_return(12);
8280 }
8281 384 }
8282
8283
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8284 {
8285
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8286 {
8287 new_return(13);
8288 }
8289 384 }
8290 128 }
8291
8292 //warp rings
8293
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8294 {
8295 new_return(14);
8296 }
8297
8298
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8299 {
8300
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8301 {
8302
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8303 {
8304 new_return(15);
8305 }
8306 1296 }
8307
8308
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8309 {
8310
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8311 {
8312 new_return(16);
8313 }
8314 1296 }
8315
8316
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8317 {
8318 new_return(17);
8319 }
8320 144 }
8321
8322 //triforce pieces
8323
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8324 {
8325
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8326 {
8327 new_return(18);
8328 }
8329 96 }
8330
8331 //end string
8332
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8333 {
8334 new_return(19);
8335 }
8336
8337 //V_MISC >= 8
8338
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8339 {
8340
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8341 {
8342
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8343 {
8344 new_return(20);
8345 }
8346 384 }
8347 128 }
8348 //V_MISC >= 9
8349
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8350 {
8351
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8352 new_return(21);
8353 384 }
8354
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8355 {
8356
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8357
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(QMisc.questmisc_strings[q][j],f))
8358 new_return(22);
8359 384 }
8360 //V_MISC >= 11
8361
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8362 new_return(23);
8363
8364 //V_MISC >= 12
8365
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8366 {
8367
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8368 new_return(24);
8369 3072 }
8370
8371 //V_MISC >= 13
8372
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8373 {
8374 768 bottletype* bt = &(QMisc.bottle_types[q]);
8375
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8376 new_return(25);
8377
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8378 {
8379
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8380 new_return(25);
8381
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8382 new_return(25);
8383 2304 }
8384
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8385 new_return(25);
8386
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8387 new_return(25);
8388 768 }
8389
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8390 {
8391 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8392
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8393 new_return(26);
8394
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8395 {
8396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8397 new_return(26);
8398
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8399 new_return(26);
8400
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8401 new_return(26);
8402
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8403 new_return(26);
8404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8405 new_return(26);
8406 9216 }
8407 3072 }
8408
8409 //V_MISC >= 14
8410
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8411 {
8412
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8413 new_return(27);
8414 3072 }
8415
8416
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8417 {
8418 6 section_size=writesize;
8419 6 }
8420 12 }
8421
8422
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8423 {
8424 char ebuf[80];
8425 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8426 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8427 }
8428
8429 6 new_return(0);
8430 }
8431
8432 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8433 {
8434 //these are here to bypass compiler warnings about unused arguments
8435 6 Header=Header;
8436
8437 6 dword section_id=ID_ITEMS;
8438 6 dword section_version=V_ITEMS;
8439 6 dword section_cversion=CV_ITEMS;
8440 // dword section_size=0;
8441 6 dword section_size = 0;
8442
8443 //section id
8444
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8445 {
8446 new_return(1);
8447 }
8448
8449 //section version info
8450
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8451 {
8452 new_return(2);
8453 }
8454
8455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8456 {
8457 new_return(3);
8458 }
8459
8460
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8461 {
8462 12 fake_pack_writing=(writecycle==0);
8463
8464 //section size
8465
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8466 {
8467 new_return(4);
8468 }
8469
8470 12 writesize=0;
8471
8472 //finally... section data
8473
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8474 {
8475 new_return(5);
8476 }
8477
8478
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8479 {
8480
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8481 {
8482 new_return(5);
8483 }
8484 3072 }
8485
8486
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8487 {
8488
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8489 {
8490 new_return(6);
8491 }
8492
8493
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8494 {
8495 new_return(7);
8496 }
8497
8498
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8499 {
8500 new_return(8);
8501 }
8502
8503
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8504 {
8505 new_return(9);
8506 }
8507
8508
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8509 {
8510 new_return(10);
8511 }
8512
8513
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8514 {
8515 new_return(11);
8516 }
8517
8518
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8519 {
8520 new_return(12);
8521 }
8522
8523
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8524 {
8525 new_return(13);
8526 }
8527
8528
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8529 {
8530 new_return(14);
8531 }
8532
8533
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8534 {
8535 new_return(14);
8536 }
8537
8538
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8539 {
8540 new_return(15);
8541 }
8542
8543
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8544 {
8545 new_return(16);
8546 }
8547
8548
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8549 {
8550 new_return(17);
8551 }
8552
8553
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8554 {
8555 new_return(18);
8556 }
8557
8558
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8559 {
8560 new_return(19);
8561 }
8562
8563
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8564 {
8565 new_return(21);
8566 }
8567
8568
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8569 {
8570 new_return(22);
8571 }
8572
8573
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8574 {
8575 new_return(23);
8576 }
8577
8578
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8579 {
8580
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8581 {
8582 new_return(24);
8583 }
8584 24576 }
8585
8586
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8587 {
8588
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8589 {
8590 new_return(25);
8591 }
8592 6144 }
8593
8594
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8595 {
8596 new_return(26);
8597 }
8598
8599
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8600 {
8601 new_return(27);
8602 }
8603
8604
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8605 {
8606 new_return(28);
8607 }
8608
8609
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8610 {
8611 new_return(29);
8612 }
8613
8614
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8615 {
8616 new_return(30);
8617 }
8618
8619
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8620 {
8621 new_return(31);
8622 }
8623
8624
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8625 {
8626 new_return(32);
8627 }
8628
8629
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8630 {
8631 new_return(33);
8632 }
8633
8634
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8635 {
8636 new_return(34);
8637 }
8638
8639
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8640 {
8641 new_return(35);
8642 }
8643
8644
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8645 {
8646 new_return(36);
8647 }
8648
8649
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8650 {
8651 new_return(37);
8652 }
8653
8654
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8655 {
8656 new_return(38);
8657 }
8658
8659
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8660 {
8661
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8662 {
8663 new_return(39);
8664 }
8665 6144 }
8666
8667
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8668 {
8669 new_return(40);
8670 }
8671
8672
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8673 {
8674 new_return(41);
8675 }
8676
8677
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8678 {
8679 new_return(42);
8680 }
8681
8682
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8683 {
8684 new_return(43);
8685 }
8686
8687
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8688 {
8689 new_return(44);
8690 }
8691
8692
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8693 {
8694 new_return(45);
8695 }
8696
8697
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8698 {
8699 new_return(46);
8700 }
8701
8702
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8703 {
8704 new_return(47);
8705 }
8706
8707
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8708 {
8709 new_return(48);
8710 }
8711
8712
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8713 {
8714 new_return(48);
8715 }
8716
8717 //New itemdata vars -Z
8718 //! version 27
8719
8720
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8721 {
8722 new_return(49);
8723 }
8724
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8725 {
8726 new_return(50);
8727 }
8728
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8729 {
8730 new_return(51);
8731 }
8732
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8733 {
8734 new_return(52);
8735 }
8736
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8737
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8738 {
8739 new_return(53);
8740 }
8741 30720 }
8742 //version 28
8743
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8744 {
8745 new_return(54);
8746 }
8747
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8748 {
8749
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8750 {
8751 new_return(55);
8752 }
8753 24576 }
8754
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8755 {
8756
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8757 {
8758 new_return(56);
8759 }
8760 6144 }
8761
8762
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8763 {
8764 new_return(57);
8765 }
8766
8767
8768
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8769 {
8770 new_return(58);
8771 }
8772
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8773 {
8774 new_return(59);
8775 }
8776
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8777 {
8778 new_return(60);
8779 }
8780
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8781 {
8782 new_return(61);
8783 }
8784
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8785 {
8786 new_return(62);
8787 }
8788
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8789 {
8790 new_return(63);
8791 }
8792
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8793 {
8794 new_return(64);
8795 }
8796
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8797 {
8798 new_return(65);
8799 }
8800
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8801 {
8802 new_return(66);
8803 }
8804
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8805 {
8806 new_return(67);
8807 }
8808
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8809 {
8810 new_return(68);
8811 }
8812
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8813 {
8814 new_return(69);
8815 }
8816
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8817 {
8818 new_return(70);
8819 }
8820
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8821 {
8822 new_return(71);
8823 }
8824
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8825 {
8826 new_return(72);
8827 }
8828
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8829 {
8830 new_return(73);
8831 }
8832
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8833 {
8834
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8835 {
8836 new_return(74);
8837 }
8838 6144 }
8839
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8840 {
8841 new_return(75);
8842 }
8843
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8844 {
8845 new_return(76);
8846 }
8847
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8848 {
8849 new_return(77);
8850 }
8851
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8852 {
8853 new_return(78);
8854 }
8855
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8856 {
8857 new_return(79);
8858 }
8859
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8860 {
8861 new_return(80);
8862 }
8863
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8864 {
8865 new_return(81);
8866 }
8867
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8868 {
8869 new_return(82);
8870 }
8871
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8872 {
8873 new_return(83);
8874 }
8875
8876
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8877 {
8878
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8879 {
8880 new_return(84);
8881 }
8882 6144 }
8883
8884 //InitD[] labels
8885
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8886 {
8887
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8888 {
8889
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8890 {
8891 new_return(85);
8892 }
8893 1597440 }
8894
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8895 {
8896
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8897 {
8898 new_return(86);
8899 }
8900 1597440 }
8901
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8902 {
8903
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8904 {
8905 new_return(87);
8906 }
8907 1597440 }
8908
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8909 {
8910 new_return(88);
8911 }
8912 24576 }
8913
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8914 {
8915
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8916 {
8917 new_return(89);
8918 }
8919
8920 6144 }
8921
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8922 {
8923 new_return(90);
8924 }
8925
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8926 {
8927 new_return(91);
8928 }
8929
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8930
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8931 new_return(92);
8932
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < BURNSPR_MAX; ++q)
8933 {
8934
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8935 new_return(93);
8936
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8937 new_return(94);
8938 15360 }
8939 3072 }
8940
8941
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8942 {
8943 6 section_size=writesize;
8944 6 }
8945 12 }
8946
8947
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8948 {
8949 char ebuf[80];
8950 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8951 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8952 }
8953
8954 6 new_return(0);
8955 }
8956
8957 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8958 {
8959 //these are here to bypass compiler warnings about unused arguments
8960 6 Header=Header;
8961
8962 6 dword section_id=ID_WEAPONS;
8963 6 dword section_version=V_WEAPONS;
8964 6 dword section_cversion=CV_WEAPONS;
8965 6 dword section_size = 0;
8966
8967 //section id
8968
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8969 {
8970 new_return(1);
8971 }
8972
8973 //section version info
8974
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8975 {
8976 new_return(2);
8977 }
8978
8979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8980 {
8981 new_return(3);
8982 }
8983
8984
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8985 {
8986 12 fake_pack_writing=(writecycle==0);
8987
8988 //section size
8989
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8990 {
8991 new_return(4);
8992 }
8993
8994 12 writesize=0;
8995
8996 //finally... section data
8997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8998 {
8999 new_return(5);
9000 }
9001
9002
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
9003 {
9004
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
9005 {
9006 new_return(5);
9007 }
9008 3072 }
9009
9010
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
9011 {
9012
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
9013 {
9014 new_return(7);
9015 }
9016
9017
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
9018 {
9019 new_return(8);
9020 }
9021
9022
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
9023 {
9024 new_return(9);
9025 }
9026
9027
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
9028 {
9029 new_return(10);
9030 }
9031
9032
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
9033 {
9034 new_return(11);
9035 }
9036
9037
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
9038 {
9039 new_return(12);
9040 }
9041
9042
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
9043 {
9044 new_return(12);
9045 }
9046 3072 }
9047
9048
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9049 {
9050 6 section_size=writesize;
9051 6 }
9052 12 }
9053
9054
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9055 {
9056 char ebuf[80];
9057 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9058 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9059 }
9060
9061 6 new_return(0);
9062 }
9063
9064 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9065 {
9066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9067 return qe_invalid;
9068
9069 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9070 4080 bool is_0x80_screen = j >= 0x80;
9071
9072
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9073 return qe_invalid;
9074
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9075 1998 return qe_OK;
9076 //Calculate what needs writing
9077 2082 uint32_t scr_has_flags = 0;
9078
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9079
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9080 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9081
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9082 290 scr_has_flags |= SCRHAS_ITEM;
9083
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9084 18 scr_has_flags |= SCRHAS_TWARP;
9085
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9086 {
9087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9088
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9089
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9090 {
9091 168 scr_has_flags |= SCRHAS_TWARP;
9092 168 break;
9093 }
9094 7586 }
9095
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9096
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9097 6 scr_has_flags |= SCRHAS_SWARP;
9098
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9099 {
9100
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9101
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9102
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9103 {
9104 1440 scr_has_flags |= SCRHAS_SWARP;
9105 1440 break;
9106 }
9107 2544 }
9108
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9109 44 scr_has_flags |= SCRHAS_WARPRET;
9110
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9111 {
9112
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9113 {
9114 588 scr_has_flags |= SCRHAS_WARPRET;
9115 588 break;
9116 }
9117 5800 }
9118
9119
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9120 scr_has_flags |= SCRHAS_LAYERS;
9121
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9122 {
9123
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9124
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9125 {
9126 192 scr_has_flags |= SCRHAS_LAYERS;
9127 192 break;
9128 }
9129 11356 }
9130
9131
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9132 4 scr_has_flags |= SCRHAS_MAZE;
9133
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9134 {
9135
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9136 {
9137 scr_has_flags |= SCRHAS_MAZE;
9138 break;
9139 }
9140 8312 }
9141
9142
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9143
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9144
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9145 1330 scr_has_flags |= SCRHAS_D_S_U;
9146
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9147 {
9148
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9149 {
9150 732 scr_has_flags |= SCRHAS_D_S_U;
9151 732 break;
9152 }
9153 80 }
9154
9155
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9156
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9157
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9158
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9159
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9160
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9161 2082 scr_has_flags |= SCRHAS_FLAGS;
9162
9163
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9164 50 scr_has_flags |= SCRHAS_ENEMY;
9165
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9166 {
9167
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9168 {
9169 640 scr_has_flags |= SCRHAS_ENEMY;
9170 640 break;
9171 }
9172 13920 }
9173
9174
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9175
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9176 6 scr_has_flags |= SCRHAS_CARRY;
9177
9178
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9179 18 scr_has_flags |= SCRHAS_SCRIPT;
9180
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9181 {
9182
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9183 {
9184 scr_has_flags |= SCRHAS_SCRIPT;
9185 break;
9186 }
9187 16512 }
9188
9189
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9190 {
9191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9192
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9193
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9194
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9195 {
9196 scr_has_flags |= SCRHAS_UNUSED;
9197 break;
9198 }
9199 20820 }
9200
9201
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9202 {
9203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9204
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9205
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9206 {
9207 1324 scr_has_flags |= SCRHAS_SECRETS;
9208 1324 break;
9209 }
9210 98028 }
9211
9212
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9213 {
9214
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9215
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9216 {
9217 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9218 1910 break;
9219 }
9220 38318 }
9221
9222
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9223
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9224
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9225 || screen.timedwarptics || screen.screen_midi != -1
9226 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9227 2082 scr_has_flags |= SCRHAS_MISC;
9228
9229
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9230 return qe_invalid;
9231
9232 //Write stuff
9233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9234 {
9235
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9236 return qe_invalid;
9237
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9238 return qe_invalid;
9239
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9240 return qe_invalid;
9241
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9244 return qe_invalid;
9245
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9246 return qe_invalid;
9247
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9248 return qe_invalid;
9249 2082 }
9250
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9251 {
9252
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9253 return qe_invalid;
9254
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9255 return qe_invalid;
9256
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9257 return qe_invalid;
9258
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9259 return qe_invalid;
9260 290 }
9261
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9262 {
9263
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9264 return qe_invalid;
9265 1500 }
9266
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9267 {
9268
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9269 {
9270
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9271 return qe_invalid;
9272 744 }
9273
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9274 {
9275
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9276 return qe_invalid;
9277 744 }
9278
9279
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9280 {
9281
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9282 return qe_invalid;
9283 744 }
9284
9285
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9286 return qe_invalid;
9287 186 }
9288
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9289 {
9290
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9291 {
9292
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9293 return qe_invalid;
9294 5784 }
9295
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9296 {
9297
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9298 return qe_invalid;
9299 5784 }
9300
9301
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9302 {
9303
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9304 return qe_invalid;
9305 5784 }
9306
9307
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9308 return qe_invalid;
9309
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9310 return qe_invalid;
9311 1446 }
9312
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9313 {
9314
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9315 {
9316
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9317 return qe_invalid;
9318 2528 }
9319
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9320 {
9321
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9322 return qe_invalid;
9323 2528 }
9324
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9325 return qe_invalid;
9326
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9327 return qe_invalid;
9328 632 }
9329
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9330 {
9331
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9332 {
9333
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9334 return qe_invalid;
9335 1152 }
9336
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9337 {
9338
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9339 return qe_invalid;
9340 1152 }
9341
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9342 {
9343
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9344 return qe_invalid;
9345 1152 }
9346
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9347 return qe_invalid;
9348
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9349 return qe_invalid;
9350 192 }
9351
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9352 {
9353
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9354 {
9355
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9356 return qe_invalid;
9357 16 }
9358
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9359 return qe_invalid;
9360 4 }
9361
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9362 {
9363
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9364 return qe_invalid;
9365
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9366 {
9367
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9368 return qe_invalid;
9369 8248 }
9370
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9371 return qe_invalid;
9372
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9373 return qe_invalid;
9374
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9375 return qe_invalid;
9376
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9377 return qe_invalid;
9378 2062 }
9379
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9380 {
9381
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9382 return qe_invalid;
9383
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9384 return qe_invalid;
9385
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9386 return qe_invalid;
9387
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9388 return qe_invalid;
9389
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9390 return qe_invalid;
9391
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9392 return qe_invalid;
9393
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9394 return qe_invalid;
9395
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9396 return qe_invalid;
9397
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9398 return qe_invalid;
9399
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9400 return qe_invalid;
9401
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9402 return qe_invalid;
9403 746 }
9404
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9405 {
9406
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9407 {
9408
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9409 return qe_invalid;
9410 6900 }
9411
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9412 return qe_invalid;
9413 690 }
9414
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9415 {
9416
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9417 return qe_invalid;
9418
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9419 return qe_invalid;
9420
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9421 return qe_invalid;
9422
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9423 return qe_invalid;
9424 6 }
9425
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9426 {
9427
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9428 return qe_invalid;
9429
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9430 return qe_invalid;
9431
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9432 {
9433
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9434 return qe_invalid;
9435 144 }
9436 18 }
9437
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9438 {
9439 for ( int32_t q = 0; q < 10; q++ )
9440 {
9441 if(!p_iputl(screen.npcstrings[q],f))
9442 return qe_invalid;
9443 }
9444 for ( int32_t q = 0; q < 10; q++ )
9445 {
9446 if(!p_iputw(screen.new_items[q],f))
9447 return qe_invalid;
9448 }
9449 for ( int32_t q = 0; q < 10; q++ )
9450 {
9451 if(!p_iputw(screen.new_item_x[q],f))
9452 return qe_invalid;
9453 }
9454 for ( int32_t q = 0; q < 10; q++ )
9455 {
9456 if(!p_iputw(screen.new_item_y[q],f))
9457 return qe_invalid;
9458 }
9459 }
9460
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9461 {
9462
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9463 {
9464
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9465 return qe_invalid;
9466 169472 }
9467
9468
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9469 {
9470
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9471 return qe_invalid;
9472 169472 }
9473
9474
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9475 {
9476
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9477 return qe_invalid;
9478 169472 }
9479 1324 }
9480
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9481 {
9482
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9483 {
9484
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9485 return qe_invalid;
9486 336160 }
9487
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9488 {
9489
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9490 return qe_invalid;
9491 336160 }
9492
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9493 {
9494
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9495 return qe_invalid;
9496 336160 }
9497 1910 }
9498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9499 {
9500
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9501 return qe_invalid;
9502
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9503 return qe_invalid;
9504
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9505 return qe_invalid;
9506
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9507 return qe_invalid;
9508
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9509 return qe_invalid;
9510
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9511 return qe_invalid;
9512
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9513 return qe_invalid;
9514
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9515 return qe_invalid;
9516
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9517 return qe_invalid;
9518
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9519 return qe_invalid;
9520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9521 return qe_invalid;
9522 2082 }
9523
9524 2082 dword numffc = screen.numFFC();
9525
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9526 return qe_invalid;
9527
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9528 {
9529 45816 ffcdata const& tempffc = screen.ffcs[k];
9530
9531
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9532 return qe_invalid;
9533
9534
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9535 44726 continue;
9536
9537
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9538 return qe_invalid;
9539
9540
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9541 return qe_invalid;
9542
9543
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9544 return qe_invalid;
9545
9546
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9547 return qe_invalid;
9548
9549
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9550 return qe_invalid;
9551
9552
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9553 return qe_invalid;
9554
9555
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9556 return qe_invalid;
9557
9558
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9559 return qe_invalid;
9560
9561
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9562 return qe_invalid;
9563
9564
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9565 return qe_invalid;
9566
9567
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9568 return qe_invalid;
9569
9570
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9571 return qe_invalid;
9572
9573
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9574 return qe_invalid;
9575
9576
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9577 return qe_invalid;
9578
9579
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9580 return qe_invalid;
9581
9582
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9583 {
9584
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9585 return qe_invalid;
9586 8720 }
9587
9588
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9589 return qe_invalid;
9590
9591
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9592 return qe_invalid;
9593 1090 }
9594
9595
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9596 return qe_invalid;
9597
9598 2082 return qe_OK;
9599 4080 }
9600
9601 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9602 {
9603 6 dword section_id=ID_MAPS;
9604 6 dword section_version=V_MAPS;
9605 6 dword section_cversion=CV_MAPS;
9606 6 dword section_size = 0;
9607
9608 //section id
9609
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9610 {
9611 new_return(1);
9612 }
9613
9614 //section version info
9615
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9616 {
9617 new_return(2);
9618 }
9619
9620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9621 {
9622 new_return(3);
9623 }
9624
9625
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9626 {
9627 12 fake_pack_writing=(writecycle==0);
9628
9629 //section size
9630
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9631 {
9632 new_return(4);
9633 }
9634
9635 12 writesize=0;
9636
9637
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9638 {
9639 new_return(5);
9640 }
9641 12 map_autolayers.resize(map_count*6);
9642
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9643 {
9644 30 byte valid = 0;
9645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9646 {
9647
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9648 break;
9649 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9650
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9651 {
9652 30 valid = 1;
9653 30 break;
9654 }
9655 210 }
9656
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9657 {
9658 new_return(6);
9659 }
9660
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9661
9662 { //per-map info
9663
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9664 {
9665 180 size_t ind = i*6+q;
9666
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9667 new_return(7);
9668 180 }
9669 }
9670
9671
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9672 4080 writemapscreen(f,i,j);
9673 30 }
9674
9675
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9676 {
9677 6 section_size=writesize;
9678 6 }
9679 12 }
9680
9681
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9682 {
9683 char ebuf[80];
9684 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9685 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9686 }
9687
9688 6 new_return(0);
9689 }
9690
9691 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9692 {
9693 //Check what needs writing
9694 byte combo_has_flags = 0;
9695 383638 for(auto q = 0; q < 8; ++q)
9696 {
9697 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9698 383638 || (q < 4 && tmp_cmb.attributes[q]))
9699 {
9700 combo_has_flags |= CHAS_ATTRIB;
9701 break;
9702 }
9703 383638 }
9704
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if(tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9705
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9706
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9707
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9708
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9709
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9710
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9711
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9712
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9713
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9714
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9715
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9716
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9717
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9718
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9719
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9720
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9721
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9722
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9723
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9724
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9725
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trig_pushtime != 8
9726
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9727
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9728 96892 combo_has_flags |= CHAS_TRIG;
9729
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9730
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9731 combo_has_flags |= CHAS_TRIG;
9732
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9733 193592 combo_has_flags |= CHAS_FLAG;
9734
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9735
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9736
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9737 196334 combo_has_flags |= CHAS_ANIM;
9738
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9739 70224 combo_has_flags |= CHAS_SCRIPT;
9740
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9741 {
9742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9743 {
9744 combo_has_flags |= CHAS_SCRIPT;
9745 break;
9746 }
9747 776032 }
9748
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9749
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9750 185268 combo_has_flags |= CHAS_BASIC;
9751
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9752
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9753
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9754
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9755
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9756
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9757
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9758 131132 combo_has_flags |= CHAS_LIFT;
9759
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9760
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9761
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9762 131132 combo_has_flags |= CHAS_GENERAL;
9763
9764
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9765 {
9766 34128 return 50;
9767 }
9768
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9769 //Write the combo
9770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9771 {
9772
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9773 return 6;
9774
9775
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9776 return 7;
9777
9778
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9779 return 8;
9780
9781
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9782 return 9;
9783
9784
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9785 return 15;
9786
9787
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9788 return 10;
9789 44820 }
9790
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9791 {
9792 p_putcstr(tmp_cmb.label, f);
9793
9794 if(!p_iputw(tmp_cmb.script,f))
9795 return 26;
9796 for ( int32_t q = 0; q < 8; q++ )
9797 if(!p_iputl(tmp_cmb.initd[q],f))
9798 return 27;
9799 }
9800
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9801 {
9802
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9803 return 11;
9804
9805
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9806 return 12;
9807
9808
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9809 return 13;
9810
9811
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9812 return 14;
9813
9814
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9815 return 16;
9816
9817
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9818 return 18;
9819
9820
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9821 return 19;
9822 17346 }
9823
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9824 {
9825
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9827 return 20;
9828
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9830 return 25;
9831
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9833 return 32;
9834 2268 }
9835
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9836 {
9837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9838 return 21;
9839
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9840 return 33;
9841 184 }
9842
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9843 {
9844
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9846 return 22;
9847
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9848 return 23;
9849
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9850 return 34;
9851
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9852 return 35;
9853
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9854 return 36;
9855
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9856 return 37;
9857
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9858 return 38;
9859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9860 return 39;
9861
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9862 return 40;
9863
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9864 return 41;
9865
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9866 return 42;
9867
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9868 return 43;
9869
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9870 return 44;
9871
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9872 return 45;
9873
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9874 return 46;
9875
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9876 return 47;
9877
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9878 return 48;
9879
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9880 return 49;
9881
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9882 return 50;
9883
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9884 return 51;
9885
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9886 return 52;
9887
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9888 return 53;
9889
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9890 return 69;
9891
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9892 return 70;
9893
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9894 return 71;
9895
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9896 return 72;
9897
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9898 return 76;
9899
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9900 return 77;
9901
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9902 return 89;
9903
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9904 return 90;
9905
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9906 return 91;
9907
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9908 return 92;
9909
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9910
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_putc(tmp_cmb.trigtint[q],f))
9911 return 93;
9912
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9913 return 94;
9914
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9915 return 95;
9916
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9917 return 96;
9918
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9919 return 97;
9920
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9921 return 98;
9922
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9923 return 99;
9924
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9925 return 100;
9926
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9927 return 101;
9928
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9929 return 102;
9930 168 }
9931
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9932 {
9933
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9934 return 54;
9935
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9936 return 55;
9937
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9938 return 56;
9939
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9940 return 57;
9941
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9942 return 58;
9943
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9944 return 59;
9945
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9946 return 60;
9947
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9948 return 61;
9949
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9950 return 62;
9951
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9952 return 63;
9953
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9954 return 64;
9955
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9956 return 65;
9957
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9958 return 66;
9959
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9960 return 67;
9961
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9962 return 68;
9963
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9964 return 78;
9965 8 }
9966
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9967 {
9968
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9969 return 73;
9970
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9971 return 74;
9972
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9973 return 75;
9974
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9975 return 79;
9976
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9977 return 80;
9978
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9979 return 81;
9980
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9981 return 82;
9982
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9983 return 83;
9984
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9985 return 84;
9986
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9987 return 85;
9988
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9989 return 86;
9990
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9991 return 87;
9992
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9993 return 88;
9994 8 }
9995 44820 return 0;
9996 131132 }
9997
9998 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9999 {
10000 //these are here to bypass compiler warnings about unused arguments
10001 6 version=version;
10002 6 build=build;
10003
10004 word combos_used;
10005 6 dword section_id=ID_COMBOS;
10006 6 dword section_version=V_COMBOS;
10007 6 dword section_cversion=CV_COMBOS;
10008 // dword section_size=0;
10009 6 combos_used = count_combos()-start_combo;
10010
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
10011
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
10012 6 dword section_size = 0;
10013
10014 //section id
10015
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10016 {
10017 new_return(1);
10018 }
10019
10020 //section version info
10021
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10022 {
10023 new_return(2);
10024 }
10025
10026
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10027 {
10028 new_return(3);
10029 }
10030
10031
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10032 {
10033 12 fake_pack_writing=(writecycle==0);
10034
10035 //section size
10036
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10037 {
10038 new_return(4);
10039 }
10040
10041 12 writesize=0;
10042
10043 //finally... section data
10044 12 combos_used=count_combos()-start_combo;
10045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
10046
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
10047
10048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10049 {
10050 new_return(5);
10051 }
10052
10053 12 size_t end_combo = start_combo+combos_used;
10054
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10055 {
10056 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10057
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10058 97004 }
10059
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10060 {
10061 6 section_size=writesize;
10062 6 }
10063 12 }
10064
10065
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10066 {
10067 char ebuf[80];
10068 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10069 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10070 }
10071
10072 6 new_return(0);
10073 6 }
10074
10075 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10076 {
10077 //these are here to bypass compiler warnings about unused arguments
10078 6 version=version;
10079 6 build=build;
10080
10081 6 dword section_id=ID_COMBOALIASES;
10082 6 dword section_version=V_COMBOALIASES;
10083 6 dword section_cversion=CV_COMBOALIASES;
10084 6 dword section_size=0;
10085
10086 //section id
10087
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10088 {
10089 new_return(1);
10090 }
10091
10092 //section version info
10093
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10094 {
10095 new_return(2);
10096 }
10097
10098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10099 {
10100 new_return(3);
10101 }
10102
10103
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10104 {
10105 12 fake_pack_writing=(writecycle==0);
10106
10107 //section size
10108
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10109 {
10110 new_return(4);
10111 }
10112
10113 12 writesize=0;
10114
10115 //finally... section data
10116
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10117 {
10118
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10119 {
10120 new_return(5);
10121 }
10122
10123
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10124 {
10125 new_return(6);
10126 }
10127
10128 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10129
10130
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10131 {
10132 new_return(7);
10133 }
10134
10135
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10136 {
10137 new_return(8);
10138 }
10139
10140
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10141 {
10142 new_return(9);
10143 }
10144
10145
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10146 {
10147
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10148 {
10149 new_return(10);
10150 }
10151 99792 }
10152
10153
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10154 {
10155
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10156 {
10157 new_return(11);
10158 }
10159 99792 }
10160 98304 }
10161
10162 //Combo pools!
10163 int16_t num_cpools;
10164
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10165 {
10166
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10167 {
10168 2 ++num_cpools;
10169 2 break;
10170 }
10171 98298 }
10172
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10173
10174
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10175 {
10176 new_return(12);
10177 }
10178
10179
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10180 {
10181 6 combo_pool const& pool = combo_pools[cp];
10182 6 int32_t num_combos = pool.combos.size();
10183
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10184 {
10185 new_return(13);
10186 }
10187
10188
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10189 {
10190 26 cpool_entry const& entry = pool.combos.at(q);
10191
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10192 {
10193 new_return(14);
10194 }
10195
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10196 {
10197 new_return(15);
10198 }
10199
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10200 {
10201 new_return(16);
10202 }
10203 26 }
10204 6 }
10205
10206 //Autocombos!
10207 int16_t num_cautos;
10208
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10209 {
10210
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10211 {
10212 ++num_cautos;
10213 break;
10214 }
10215 98304 }
10216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10217
10218
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10219 {
10220 new_return(17);
10221 }
10222
10223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10224 {
10225 combo_auto const& cauto = combo_autos[ca];
10226 if (!p_putc(cauto.getType(), f))
10227 {
10228 new_return(18);
10229 }
10230 if (!p_iputl(cauto.getIconDisplay(), f))
10231 {
10232 new_return(19);
10233 }
10234 if (!p_iputl(cauto.getEraseCombo(), f))
10235 {
10236 new_return(20);
10237 }
10238 if (!p_putc(cauto.getFlags(), f))
10239 {
10240 new_return(21);
10241 }
10242 if (!p_putc(cauto.getArg(), f))
10243 {
10244 new_return(22);
10245 }
10246 int32_t num_combos = cauto.combos.size();
10247 if (!p_iputl(num_combos, f))
10248 {
10249 new_return(23);
10250 }
10251
10252 for (auto q = 0; q < num_combos; ++q)
10253 {
10254 autocombo_entry const& entry = cauto.combos.at(q);
10255 if (!p_putc(entry.ctype, f))
10256 {
10257 new_return(24);
10258 }
10259 if (!p_iputl(entry.cid, f))
10260 {
10261 new_return(25);
10262 }
10263 }
10264 }
10265
10266
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10267 {
10268 6 section_size=writesize;
10269 6 }
10270 12 }
10271
10272
10273
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10274 {
10275 char ebuf[80];
10276 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10277 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10278 }
10279
10280 6 new_return(0);
10281 }
10282
10283 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10284 {
10285 //these are here to bypass compiler warnings about unused arguments
10286 6 version=version;
10287 6 build=build;
10288 6 start_cset=start_cset;
10289 6 max_csets=max_csets;
10290
10291 6 dword section_id=ID_CSETS;
10292 6 dword section_version=V_CSETS;
10293 6 dword section_cversion=CV_CSETS;
10294 6 int32_t palcycles = count_palcycles(&QMisc);
10295 // int32_t palcyccount = count_palcycles(&QMisc);
10296 6 dword section_size = 0;
10297
10298 //section id
10299
10300
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10301 {
10302 new_return(1);
10303 }
10304
10305 //section version info
10306
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10307 {
10308 new_return(2);
10309 }
10310
10311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10312 {
10313 new_return(3);
10314 }
10315
10316
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10317 {
10318 12 fake_pack_writing=(writecycle==0);
10319
10320 //section size
10321
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10322 {
10323 new_return(4);
10324 }
10325
10326 12 writesize=0;
10327
10328 //finally... section data
10329
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10330 {
10331 new_return(5);
10332 }
10333
10334
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10335 {
10336 new_return(6);
10337 }
10338
10339
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10340 {
10341 new_return(15);
10342 }
10343
10344
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10345 {
10346
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10347 {
10348
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10349 {
10350 new_return(16);
10351 }
10352 828 }
10353
10354
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10355 {
10356
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10357 {
10358 new_return(17);
10359 }
10360 828 }
10361
10362
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10363 {
10364
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10365 {
10366 new_return(18);
10367 }
10368 828 }
10369 276 }
10370
10371
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10372 {
10373 6 section_size=writesize;
10374 6 }
10375 12 }
10376
10377
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10378 {
10379 char ebuf[80];
10380 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10381 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10382 }
10383
10384 6 new_return(0);
10385 }
10386
10387 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10388 {
10389 //these are here to bypass compiler warnings about unused arguments
10390 6 version=version;
10391 6 build=build;
10392 6 start_msgstr=start_msgstr;
10393 6 max_msgstrs=max_msgstrs;
10394
10395 6 dword section_id=ID_STRINGS;
10396 6 dword section_version=V_STRINGS;
10397 6 dword section_cversion=CV_STRINGS;
10398 6 dword section_size = 0;
10399
10400 //section id
10401
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10402 {
10403 new_return(1);
10404 }
10405
10406 //section version info
10407
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10408 {
10409 new_return(2);
10410 }
10411
10412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10413 {
10414 new_return(3);
10415 }
10416
10417
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10418 {
10419 12 fake_pack_writing=(writecycle==0);
10420
10421 //section size
10422
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10423 {
10424 new_return(4);
10425 }
10426
10427 12 writesize=0;
10428
10429 //finally... section data
10430
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10431 {
10432 return qe_invalid;
10433 }
10434
10435
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10436 {
10437 302 int32_t sz = MsgStrings[i].s.size();
10438
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10439
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10440 {
10441 return qe_invalid;
10442 }
10443
10444 302 char const* tmpstr = MsgStrings[i].s.c_str();
10445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10446 {
10447
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10448 {
10449 return qe_invalid;
10450 }
10451 302 }
10452
10453
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10454 {
10455 return qe_invalid;
10456 }
10457
10458
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10459 {
10460 return qe_invalid;
10461 }
10462
10463
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10464 {
10465 return qe_invalid;
10466 }
10467
10468
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10469 {
10470 return qe_invalid;
10471 }
10472
10473
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10474 {
10475 return qe_invalid;
10476 }
10477
10478
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10479 {
10480 return qe_invalid;
10481 }
10482
10483
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10484 {
10485 return qe_invalid;
10486 }
10487
10488
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10489 {
10490 return qe_invalid;
10491 }
10492
10493
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10494 {
10495 return qe_invalid;
10496 }
10497
10498
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10499 {
10500 return qe_invalid;
10501 }
10502
10503
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10504 {
10505 return qe_invalid;
10506 }
10507
10508
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10509 {
10510 return qe_invalid;
10511 }
10512
10513
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10514 {
10515
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10516 {
10517 return qe_invalid;
10518 }
10519 1208 }
10520
10521
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10522 {
10523 return qe_invalid;
10524 }
10525
10526
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10527 {
10528 return qe_invalid;
10529 }
10530
10531
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10532 {
10533 return qe_invalid;
10534 }
10535
10536
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10537 {
10538 return qe_invalid;
10539 }
10540
10541
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10542 {
10543 return qe_invalid;
10544 }
10545
10546
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10547 {
10548 return qe_invalid;
10549 }
10550
10551
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10552 {
10553 return qe_invalid;
10554 }
10555
10556
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10557 {
10558 return qe_invalid;
10559 }
10560
10561
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10562 {
10563 return qe_invalid;
10564 }
10565
10566
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10567 {
10568 return qe_invalid;
10569 }
10570
10571
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10572 {
10573 return qe_invalid;
10574 }
10575 302 }
10576
10577
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10578 {
10579 6 section_size=writesize;
10580 6 }
10581 12 }
10582
10583
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10584 {
10585 char ebuf[80];
10586 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10587 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10588 }
10589
10590 6 new_return(0);
10591 6 }
10592
10593 int32_t writestrings_text(PACKFILE *f)
10594 {
10595 std::map<int32_t, int32_t> msglistcache;
10596
10597 for(int32_t index = 1; index<msg_count; index++)
10598 {
10599 for(int32_t i=1; i<msg_count; i++)
10600 {
10601 if(MsgStrings[i].listpos==index)
10602 {
10603 msglistcache[index-1]=i;
10604 break;
10605 }
10606 }
10607 }
10608
10609 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10610 {
10611 fake_pack_writing=(writecycle==0);
10612 char ebuf[32];
10613
10614 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10615
10616 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10617 {
10618 return qe_invalid;
10619 }
10620
10621 for(int32_t i=1; i<msg_count; i++)
10622 {
10623 int32_t str = msglistcache[i-1];
10624
10625 if(!str)
10626 continue;
10627
10628 if(MsgStrings[str].nextstring != 0)
10629 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10630 else
10631 sprintf(ebuf,"\n\n___%d___\n", str);
10632
10633 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10634 {
10635 return qe_invalid;
10636 }
10637
10638 encode_msg_str(str);
10639
10640 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10641 {
10642 return qe_invalid;
10643 }
10644 }
10645 }
10646
10647 new_return(0);
10648 }
10649
10650 1 int32_t writestrings_tsv(PACKFILE *f)
10651 {
10652 1 std::stringstream ss;
10653
10654 int32_t str;
10655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10656
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10657 35 encode_msg_str(str);
10658 35 return msgbuf;
10659 }},
10660
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10661
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10662
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10663
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10664
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10666
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10668
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10671
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10672
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10673
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10674
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10675
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10676
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10677
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10678
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10679
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10680
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10681
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10682
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10683
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10684 };
10685
10686
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10687 {
10688
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10689
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10690 1 break;
10691
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10692 }
10693
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10694
10695 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10696
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10697
10698
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10699 {
10700 35 str = i;
10701 35 auto& msg = MsgStrings[str];
10702
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10703 {
10704
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10705
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10706
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10707 35 break;
10708
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10709
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10710
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10711 35 }
10712
10713
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10714
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10715 {
10716 return qe_invalid;
10717 }
10718
10719 1 new_return(0);
10720 1 }
10721
10722 void parse_strings_tsv(std::string tsv)
10723 {
10724 std::string parse_msg_str(std::string const& s);
10725 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10726 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10727 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10728 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10729 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10730 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10731 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10732 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10733 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10734 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10735 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10736 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10737 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10738 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10739 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10740 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10741 { "margin", [&](auto& msg, auto& text){
10742 std::vector<std::string> strs;
10743 util::split(text, strs, ' ');
10744 if (strs.size() != 4)
10745 throw std::runtime_error("margin field must have 4 components");
10746 msg.margins[0] = std::stoi(strs[0]);
10747 msg.margins[1] = std::stoi(strs[1]);
10748 msg.margins[2] = std::stoi(strs[2]);
10749 msg.margins[3] = std::stoi(strs[3]);
10750 } },
10751 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10752 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10753 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10754 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10755 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10756 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10757 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10758 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10759 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10760 };
10761
10762 std::vector<std::string> rows;
10763 util::split(tsv, rows, '\n');
10764 if (rows.size())
10765 {
10766 std::string last = rows.back();
10767 util::trimstr(last);
10768 if (last.empty())
10769 rows.pop_back();
10770 }
10771 if (rows.size() <= 1)
10772 throw std::runtime_error("missing header row");
10773
10774 std::vector<std::string> columns;
10775 util::split(rows[0], columns, '\t');
10776 for (auto name : columns)
10777 {
10778 if (!fields.contains(name))
10779 throw std::runtime_error(fmt::format("invalid field: {}", name));
10780 }
10781
10782 int start_index = 1;
10783 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10784 start_index += 1;
10785
10786 int num_strings = rows.size() - start_index + 1;
10787 if (num_strings > MAXMSGS-1)
10788 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10789
10790 std::vector<MsgStr> msgs;
10791 msgs.reserve(num_strings);
10792 for (int i = start_index; i < rows.size(); i++)
10793 {
10794 std::vector<std::string> strs;
10795 util::split(rows[i], strs, '\t');
10796 if (strs.size() != columns.size())
10797 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10798
10799 int j = 0;
10800 auto& msg = msgs.emplace_back();
10801 for (auto& name : columns)
10802 {
10803 auto& fn = fields[name];
10804 try
10805 {
10806 fn(msg, strs[j++]);
10807 }
10808 catch (std::exception& ex)
10809 {
10810 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10811 }
10812 }
10813 }
10814
10815 init_msgstrings(0, msgs.size());
10816 for (int i = 0; i < msgs.size(); i++)
10817 MsgStrings[i + 1] = msgs[i];
10818 msg_count = msgs.size();
10819 msglistcache.clear();
10820 }
10821
10822 bool isblanktile(tiledata *buf, int32_t i);
10823 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10824 {
10825 //these are here to bypass compiler warnings about unused arguments
10826 6 version=version;
10827 6 build=build;
10828
10829 int32_t tiles_used;
10830 6 dword section_id=ID_TILES;
10831 6 dword section_version=V_TILES;
10832 6 dword section_cversion=CV_TILES;
10833 6 al_trace("Counting tiles used\n");
10834 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10835
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10836
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10837 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10838 6 dword section_size = 0;
10839
10840 //section id
10841
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10842 {
10843 new_return(1);
10844 }
10845
10846 //section version info
10847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10848 {
10849 new_return(2);
10850 }
10851
10852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10853 {
10854 new_return(3);
10855 }
10856
10857
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10858 {
10859 12 fake_pack_writing=(writecycle==0);
10860
10861 //section size
10862
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10863 {
10864 new_return(4);
10865 }
10866
10867 12 writesize=0;
10868
10869 //finally... section data
10870 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10871
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10872
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10873
10874
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10875 {
10876 new_return(5);
10877 }
10878
10879
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10880 {
10881
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10882 {
10883
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10884 new_return(8);
10885 238750 }
10886 else
10887 {
10888 209304 int format = newtilebuf[start_tile+i].format;
10889
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10890 {
10891 new_return(6);
10892 }
10893
10894
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10895 {
10896 byte temp_tile[128];
10897 207706 byte *di = temp_tile;
10898 207706 byte *src = newtilebuf[start_tile+i].data;
10899
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10900 {
10901 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10902 26586368 ++di;
10903 26586368 }
10904
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10905 {
10906 new_return(7);
10907 }
10908 207706 }
10909
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10910 {
10911 new_return(7);
10912 }
10913 }
10914 448054 }
10915
10916
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10917 {
10918 6 section_size=writesize;
10919 6 }
10920 12 }
10921
10922
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10923 {
10924 char ebuf[80];
10925 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10926 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10927 }
10928
10929 6 new_return(0);
10930 }
10931
10932 /* MIDI Format
10933 section_id LONG
10934 section_version WORD
10935 section_cversion WORD
10936 section_size LONG
10937 midi_flags 32 Byte ? BITFIELD[252]
10938
10939 [
10940 title 36
10941 start 4
10942 loop_start 4
10943 loop_end 4
10944 loop 2
10945 volume 2
10946 midi *
10947 ]
10948
10949 */
10950
10951 6 int32_t writemidis(PACKFILE *f)
10952 {
10953 6 dword section_id=ID_MIDIS;
10954 6 dword section_version=V_MIDIS;
10955 6 dword section_cversion=CV_MIDIS;
10956 6 dword section_size = 0;
10957
10958 //section id
10959
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10960 {
10961 new_return(1);
10962 }
10963
10964 //section version info
10965
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10966 {
10967 new_return(2);
10968 }
10969
10970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10971 {
10972 new_return(3);
10973 }
10974
10975
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10976 {
10977 12 fake_pack_writing=(writecycle==0);
10978
10979 //section size
10980
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10981 {
10982 new_return(4);
10983 }
10984
10985 12 writesize=0;
10986
10987 //finally... section data
10988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10989 {
10990 new_return(5);
10991 }
10992
10993
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10994 {
10995
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10996 {
10997
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10998 {
10999 new_return(6);
11000 }
11001
11002
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
11003 {
11004 new_return(7);
11005 }
11006
11007
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
11008 {
11009 new_return(8);
11010 }
11011
11012
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
11013 {
11014 new_return(9);
11015 }
11016
11017
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
11018 {
11019 new_return(10);
11020 }
11021
11022
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
11023 {
11024 new_return(11);
11025 }
11026
11027
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
11028 {
11029 new_return(12);
11030 }
11031
11032
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].format, sizeof(customtunes[i].format),f))
11033 {
11034 new_return(13);
11035 }
11036
11037
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 switch(customtunes[i].format)
11038 {
11039 case MFORMAT_MIDI:
11040
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!write_midi((MIDI*) customtunes[i].data,f)) new_return(14);
11041
11042 60 break;
11043
11044 default:
11045 new_return(15);
11046 break;
11047 }
11048 60 }
11049 3024 }
11050
11051
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11052 {
11053 6 section_size=writesize;
11054 6 }
11055 12 }
11056
11057
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11058 {
11059 char ebuf[80];
11060 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11061 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11062 }
11063
11064 6 new_return(0);
11065 }
11066
11067 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11068 {
11069 6 dword section_id=ID_CHEATS;
11070 6 dword section_version=V_CHEATS;
11071 6 dword section_cversion=CV_CHEATS;
11072 6 dword section_size = 0;
11073
11074 //section id
11075
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11076 {
11077 new_return(1);
11078 }
11079
11080 //section version info
11081
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11082 {
11083 new_return(2);
11084 }
11085
11086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11087 {
11088 new_return(3);
11089 }
11090
11091
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11092 {
11093 12 fake_pack_writing=(writecycle==0);
11094
11095 //section size
11096
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11097 {
11098 new_return(4);
11099 }
11100
11101 12 writesize=0;
11102
11103 //finally... section data
11104
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11105 {
11106 new_return(5);
11107 }
11108
11109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11110 {
11111
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11112 {
11113 new_return(6);
11114 }
11115
11116
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11117 {
11118 new_return(7);
11119 }
11120 12 }
11121
11122
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11123 {
11124 6 section_size=writesize;
11125 6 }
11126 12 }
11127
11128
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11129 {
11130 char ebuf[80];
11131 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11132 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11133 }
11134
11135 6 new_return(0);
11136 }
11137
11138 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11139 {
11140 //these are here to bypass compiler warnings about unused arguments
11141 6 Header=Header;
11142
11143 6 dword section_id=ID_GUYS;
11144 6 dword section_version=V_GUYS;
11145 6 dword section_cversion=CV_GUYS;
11146 6 dword section_size=0;
11147
11148 //section id
11149
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11150 {
11151 new_return(1);
11152 }
11153
11154 //section version info
11155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11156 {
11157 new_return(2);
11158 }
11159
11160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11161 {
11162 new_return(3);
11163 }
11164
11165
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11166 {
11167 12 fake_pack_writing=(writecycle==0);
11168
11169 //section size
11170
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11171 {
11172 new_return(4);
11173 }
11174
11175 12 writesize=0;
11176
11177 //finally... section data
11178
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11179 {
11180
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11181 {
11182 new_return(5);
11183 }
11184 6144 }
11185
11186
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6144 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11187 {
11188
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags,f))
11189 {
11190 new_return(6);
11191 }
11192
11193
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags2,f))
11194 {
11195 new_return(7);
11196 }
11197
11198
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11199 {
11200 new_return(8);
11201 }
11202
11203
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11204 {
11205 new_return(9);
11206 }
11207
11208
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11209 {
11210 new_return(10);
11211 }
11212
11213
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11214 {
11215 new_return(11);
11216 }
11217
11218
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11219 {
11220 new_return(12);
11221 }
11222
11223
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11224 {
11225 new_return(13);
11226 }
11227
11228
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11229 {
11230 new_return(14);
11231 }
11232
11233
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11234 {
11235 new_return(15);
11236 }
11237
11238
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11239 {
11240 new_return(16);
11241 }
11242
11243
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11244 {
11245 new_return(17);
11246 }
11247
11248
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11249 {
11250 new_return(18);
11251 }
11252
11253
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11254 {
11255 new_return(19);
11256 }
11257
11258
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11259 {
11260 new_return(20);
11261 }
11262
11263
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11264 {
11265 new_return(21);
11266 }
11267
11268
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11269 {
11270 new_return(22);
11271 }
11272
11273
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11274 {
11275 new_return(23);
11276 }
11277
11278
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11279 {
11280 new_return(24);
11281 }
11282
11283
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11284 {
11285 new_return(25);
11286 }
11287
11288
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11289 {
11290 new_return(26);
11291 }
11292
11293
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11294 {
11295 new_return(27);
11296 }
11297
11298
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11299 {
11300 new_return(28);
11301 }
11302
11303
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11304 {
11305 new_return(29);
11306 }
11307
11308
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11309 {
11310 new_return(30);
11311 }
11312
11313
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11314 {
11315 new_return(31);
11316 }
11317
11318
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11319 {
11320 new_return(32);
11321 }
11322
11323
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc1,f))
11324 {
11325 new_return(33);
11326 }
11327
11328
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc2,f))
11329 {
11330 new_return(34);
11331 }
11332
11333
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc3,f))
11334 {
11335 new_return(35);
11336 }
11337
11338
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc4,f))
11339 {
11340 new_return(36);
11341 }
11342
11343
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc5,f))
11344 {
11345 new_return(37);
11346 }
11347
11348
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc6,f))
11349 {
11350 new_return(38);
11351 }
11352
11353
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc7,f))
11354 {
11355 new_return(39);
11356 }
11357
11358
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc8,f))
11359 {
11360 new_return(40);
11361 }
11362
11363
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc9,f))
11364 {
11365 new_return(41);
11366 }
11367
11368
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc10,f))
11369 {
11370 new_return(42);
11371 }
11372
11373
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11374 {
11375 new_return(43);
11376 }
11377
11378
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11379 {
11380 new_return(44);
11381 }
11382
11383
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11384 {
11385 new_return(45);
11386 }
11387
11388
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11389 {
11390
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11391 {
11392 new_return(46);
11393 }
11394 116736 }
11395
11396
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11397 {
11398 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11399 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11400 //Force SFX_HIT here.
11401
11402 }
11403
11404
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11405 {
11406 new_return(47);
11407 }
11408
11409
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11410 {
11411 new_return(48);
11412 }
11413
11414
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc11,f))
11415 {
11416 new_return(49);
11417 }
11418
11419
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc12,f))
11420 {
11421 new_return(50);
11422 }
11423
11424 //New 2.6 defences
11425
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11426 {
11427
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11428 {
11429 new_return(51);
11430 }
11431 135168 }
11432
11433 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11434
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11435 {
11436 new_return(52);
11437 }
11438
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11439 {
11440 new_return(53);
11441 }
11442
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11443 {
11444 new_return(54);
11445 }
11446
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11447 {
11448 new_return(55);
11449 }
11450
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11451 {
11452 new_return(56);
11453 }
11454 // These are not fixed types, but ints, so they are safe to use here.
11455
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11456 {
11457 new_return(57);
11458 }
11459
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11460 {
11461 new_return(58);
11462 }
11463
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11464 {
11465 new_return(59);
11466 }
11467
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11468 {
11469 new_return(60);
11470 }
11471
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11472 {
11473 new_return(61);
11474 }
11475
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11476 {
11477 new_return(62);
11478 }
11479
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11480 {
11481 new_return(63);
11482 }
11483
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11484 {
11485 new_return(64);
11486 }
11487
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11488 {
11489 new_return(65);
11490 }
11491
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11492 {
11493 new_return(66);
11494 }
11495
11496
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11497 {
11498
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11499 {
11500 new_return(67);
11501 }
11502 61440 }
11503
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11504 {
11505 new_return(68);
11506 }
11507 //misc 16->31
11508
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc16,f))
11509 {
11510 new_return(69);
11511 }
11512
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc17,f))
11513 {
11514 new_return(70);
11515 }
11516
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc18,f))
11517 {
11518 new_return(71);
11519 }
11520
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc19,f))
11521 {
11522 new_return(72);
11523 }
11524
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc20,f))
11525 {
11526 new_return(73);
11527 }
11528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc21,f))
11529 {
11530 new_return(74);
11531 }
11532
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc22,f))
11533 {
11534 new_return(75);
11535 }
11536
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc23,f))
11537 {
11538 new_return(76);
11539 }
11540
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc24,f))
11541 {
11542 new_return(77);
11543 }
11544
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc25,f))
11545 {
11546 new_return(78);
11547 }
11548
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc26,f))
11549 {
11550 new_return(79);
11551 }
11552
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc27,f))
11553 {
11554 new_return(80);
11555 }
11556
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc28,f))
11557 {
11558 new_return(81);
11559 }
11560
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc29,f))
11561 {
11562 new_return(82);
11563 }
11564
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc30,f))
11565 {
11566 new_return(83);
11567 }
11568
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc31,f))
11569 {
11570 new_return(84);
11571 }
11572
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc32,f))
11573 {
11574 new_return(85);
11575 }
11576
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11577 {
11578
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11579 {
11580 new_return(86);
11581 }
11582 196608 }
11583
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11584 {
11585
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11586 {
11587 new_return(87);
11588 }
11589 196608 }
11590
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11591 {
11592 new_return(88);
11593 }
11594
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11595 {
11596
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11597 {
11598 new_return(89);
11599 }
11600 49152 }
11601
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11602 {
11603
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11604 {
11605 new_return(90);
11606 }
11607 12288 }
11608
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11609 {
11610 new_return(91);
11611 }
11612 //somehow forgot these in the older builds -Z
11613
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc13,f))
11614 {
11615 new_return(92);
11616 }
11617
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc14,f))
11618 {
11619 new_return(93);
11620 }
11621
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc15,f))
11622 {
11623 new_return(94);
11624 }
11625
11626 //Enemy Editor InitD[] labels
11627
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11628 {
11629
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11630 {
11631
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11632 {
11633 new_return(95);
11634 }
11635 3194880 }
11636
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11637 {
11638
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11639 {
11640 new_return(96);
11641 }
11642 3194880 }
11643 49152 }
11644
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11645 {
11646 new_return(97);
11647 }
11648 //eweapon initD
11649
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11650 {
11651
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11652 {
11653 new_return(98);
11654 }
11655 49152 }
11656
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11657 new_return(99);
11658
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11659 new_return(100);
11660
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11661 new_return(101);
11662
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11663 new_return(102);
11664 6144 }
11665
11666
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11667 {
11668 6 section_size=writesize;
11669 6 }
11670 12 }
11671
11672
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11673 {
11674 char ebuf[80];
11675 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11676 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11677 }
11678
11679 6 new_return(0);
11680 }
11681
11682 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11683 {
11684 //these are here to bypass compiler warnings about unused arguments
11685 6 Header=Header;
11686
11687 6 dword section_id=ID_HEROSPRITES;
11688 6 dword section_version=V_HEROSPRITES;
11689 6 dword section_cversion=CV_HEROSPRITES;
11690 6 dword section_size=0;
11691
11692 //section id
11693
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11694 {
11695 new_return(1);
11696 }
11697
11698 //section version info
11699
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11700 {
11701 new_return(2);
11702 }
11703
11704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11705 {
11706 new_return(3);
11707 }
11708
11709
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11710 {
11711 12 fake_pack_writing=(writecycle==0);
11712
11713 //section size
11714
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11715 {
11716 new_return(4);
11717 }
11718
11719 12 writesize=0;
11720
11721 //finally... section data
11722
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11723 {
11724
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11725 {
11726 new_return(5);
11727 }
11728
11729
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11730 {
11731 new_return(5);
11732 }
11733
11734
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11735 {
11736 new_return(5);
11737 }
11738 48 }
11739
11740
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11741 {
11742
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11743 {
11744 new_return(6);
11745 }
11746
11747
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11748 {
11749 new_return(6);
11750 }
11751
11752
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11753 {
11754 new_return(6);
11755 }
11756 48 }
11757
11758
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11759 {
11760
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11761 {
11762 new_return(7);
11763 }
11764
11765
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11766 {
11767 new_return(7);
11768 }
11769
11770
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11771 {
11772 new_return(7);
11773 }
11774 48 }
11775
11776
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11777 {
11778
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11779 {
11780 new_return(8);
11781 }
11782
11783
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11784 {
11785 new_return(8);
11786 }
11787
11788
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11789 {
11790 new_return(8);
11791 }
11792 48 }
11793
11794
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11795 {
11796
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11797 {
11798 new_return(8);
11799 }
11800
11801
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11802 {
11803 new_return(8);
11804 }
11805
11806
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11807 {
11808 new_return(8);
11809 }
11810 48 }
11811
11812
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11813 {
11814
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11815 {
11816 new_return(9);
11817 }
11818
11819
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11820 {
11821 new_return(9);
11822 }
11823
11824
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11825 {
11826 new_return(9);
11827 }
11828 48 }
11829
11830
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11831 {
11832
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11833 {
11834 new_return(10);
11835 }
11836
11837
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11838 {
11839 new_return(10);
11840 }
11841
11842
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11843 {
11844 new_return(10);
11845 }
11846 48 }
11847
11848
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11849 {
11850 new_return(11);
11851 }
11852
11853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11854 {
11855 new_return(11);
11856 }
11857
11858
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11859 {
11860 new_return(11);
11861 }
11862
11863
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11864 {
11865
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11866 {
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11868 {
11869 new_return(12);
11870 }
11871
11872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11873 {
11874 new_return(12);
11875 }
11876
11877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11878 {
11879 new_return(12);
11880 }
11881 72 }
11882 24 }
11883
11884
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11885 {
11886
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11887 {
11888 new_return(13);
11889 }
11890
11891
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11892 {
11893 new_return(13);
11894 }
11895
11896
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11897 {
11898 new_return(13);
11899 }
11900 48 }
11901
11902
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11903 {
11904
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11905 {
11906 new_return(13);
11907 }
11908
11909
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11910 {
11911 new_return(13);
11912 }
11913
11914
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11915 {
11916 new_return(13);
11917 }
11918 48 }
11919
11920
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11921 {
11922 new_return(14);
11923 }
11924
11925 //{ V_HEROSPRITES >= 7
11926
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11933 new_return(15);
11934 48 }
11935
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11942 new_return(15);
11943 48 }
11944
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11951 new_return(15);
11952 48 }
11953
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11960 new_return(15);
11961 48 }
11962
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11963 {
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11969 new_return(15);
11970 48 }
11971
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11974 new_return(15);
11975
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11976 new_return(15);
11977
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11978 new_return(15);
11979 48 }
11980
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11985 new_return(15);
11986
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11987 new_return(15);
11988 48 }
11989
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11990 {
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11994 new_return(15);
11995
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11996 new_return(15);
11997 48 }
11998
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11999 {
12000
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
12001 new_return(15);
12002
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
12003 new_return(15);
12004
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
12005 new_return(15);
12006
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
12007 new_return(15);
12008 48 }
12009
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12010 {
12011
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
12012 new_return(15);
12013
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
12014 new_return(15);
12015
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
12016 new_return(15);
12017 48 }
12018
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12019 {
12020
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
12021 new_return(15);
12022
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12023 new_return(15);
12024
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12025 new_return(15);
12026 48 }
12027
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12028 {
12029
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12030 new_return(15);
12031
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12032 new_return(15);
12033
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12034 new_return(15);
12035 48 }
12036
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12037 {
12038
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12039 new_return(15);
12040
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12041 new_return(15);
12042
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12043 new_return(15);
12044 48 }
12045
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12046 {
12047
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12048 new_return(15);
12049
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12050 new_return(15);
12051
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12052 new_return(15);
12053 48 }
12054
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12055 {
12056
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12057 new_return(15);
12058
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12059 new_return(15);
12060
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12061 new_return(15);
12062 48 }
12063
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12064 {
12065
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12066 new_return(15);
12067
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12068 new_return(15);
12069
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12070 new_return(15);
12071 48 }
12072
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12073 {
12074
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12075 new_return(15);
12076
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12077 new_return(15);
12078
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12079 new_return(15);
12080 48 }
12081
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12082 {
12083
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12084 new_return(15);
12085
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12086 new_return(15);
12087
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12088 new_return(15);
12089 48 }
12090
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12091 {
12092
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12093 new_return(15);
12094
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12095 new_return(15);
12096
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12097 new_return(15);
12098 48 }
12099
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12100 {
12101
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12102 new_return(15);
12103
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12104 new_return(15);
12105
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12106 new_return(15);
12107 48 }
12108
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12109 {
12110
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12111 new_return(15);
12112
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12113 new_return(15);
12114
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12115 new_return(15);
12116 48 }
12117
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12118 {
12119
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12120 new_return(15);
12121
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12122 new_return(15);
12123
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12124 new_return(15);
12125 48 }
12126
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12127 {
12128
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12129 new_return(15);
12130
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12131 new_return(15);
12132
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12133 new_return(15);
12134 48 }
12135
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12136 {
12137
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12138 new_return(15);
12139
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12140 new_return(15);
12141
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12142 new_return(15);
12143 36 }
12144
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12145 {
12146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12147 new_return(16);
12148
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12149 new_return(16);
12150
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12151 new_return(16);
12152 48 }
12153
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12154 {
12155
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12156 new_return(17);
12157
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12158 new_return(17);
12159
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12160 new_return(17);
12161 48 }
12162
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12163 {
12164
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12165 new_return(17);
12166
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12167 new_return(17);
12168
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12169 new_return(17);
12170 48 }
12171
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12172 {
12173
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12174 new_return(17);
12175
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12176 new_return(17);
12177
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12178 new_return(17);
12179 48 }
12180
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12181 {
12182
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12183 new_return(18);
12184
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12185 new_return(18);
12186
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12187 new_return(18);
12188 48 }
12189
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12190 {
12191
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12192 new_return(19);
12193 48 }
12194
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12195 {
12196
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12197 new_return(20);
12198
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12199 new_return(20);
12200
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12201 new_return(20);
12202 36 }
12203
12204
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12205 {
12206 new_return(21);
12207 }
12208
12209
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12210 {
12211 new_return(21);
12212 }
12213
12214
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12215 {
12216 new_return(21);
12217 }
12218
12219
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12220 {
12221
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12222 new_return(22);
12223
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12224 new_return(22);
12225
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12226 new_return(22);
12227 48 }
12228
12229
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12230 {
12231
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12232 {
12233 new_return(23);
12234 }
12235
12236
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12237 {
12238 new_return(23);
12239 }
12240
12241
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12242 {
12243 new_return(23);
12244 }
12245 48 }
12246
12247
12248
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12249 {
12250
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12251 new_return(15);
12252 1752 }
12253 //}
12254
12255
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12256 {
12257 6 section_size=writesize;
12258 6 }
12259 12 }
12260
12261 //More data will come here
12262
12263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12264 {
12265 char ebuf[80];
12266 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12267 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12268 }
12269
12270 6 new_return(0);
12271 }
12272
12273 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12274 {
12275 6 dword section_id=ID_SUBSCREEN;
12276 6 dword section_version=V_SUBSCREEN;
12277 6 dword section_cversion=CV_SUBSCREEN;
12278 6 dword section_size=0;
12279
12280 //section id
12281
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12282 {
12283 new_return(1);
12284 }
12285
12286 //section version info
12287
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12288 {
12289 new_return(2);
12290 }
12291
12292
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12293 {
12294 new_return(3);
12295 }
12296
12297
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12298 {
12299 12 fake_pack_writing=(writecycle==0);
12300
12301 //section size
12302
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12303 {
12304 new_return(4);
12305 }
12306
12307 12 writesize=0;
12308
12309 12 byte sz = subscreens_active.size();
12310
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12311 new_return(5);
12312
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12313 {
12314 66 int32_t ret = subscreens_active[i].write(f);
12315 66 fake_pack_writing=(writecycle==0);
12316
12317
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12318 new_return(ret);
12319 66 }
12320
12321 12 sz = subscreens_passive.size();
12322
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12323 new_return(5);
12324
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12325 {
12326 50 int32_t ret = subscreens_passive[i].write(f);
12327 50 fake_pack_writing=(writecycle==0);
12328
12329
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12330 new_return(ret);
12331 50 }
12332
12333 12 sz = subscreens_overlay.size();
12334
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12335 new_return(5);
12336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12337 {
12338 int32_t ret = subscreens_overlay[i].write(f);
12339 fake_pack_writing=(writecycle==0);
12340
12341 if(ret!=0)
12342 new_return(ret);
12343 }
12344
12345
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12346 {
12347 6 section_size=writesize;
12348 6 }
12349 12 }
12350
12351
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12352 {
12353 char ebuf[80];
12354 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12355 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12356 }
12357
12358 6 new_return(0);
12359 6 }
12360
12361 extern script_data *ffscripts[NUMSCRIPTFFC];
12362 extern script_data *itemscripts[NUMSCRIPTITEM];
12363 extern script_data *guyscripts[NUMSCRIPTGUYS];
12364 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12365 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12366 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12367 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12368 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12369 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12370 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12371 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12372 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12373 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12374
12375 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12376 {
12377 6 dword section_id = ID_FFSCRIPT;
12378 6 dword section_version = V_FFSCRIPT;
12379 6 dword section_cversion = CV_FFSCRIPT;
12380 6 dword section_size = 0;
12381 6 dword zasmmeta_version = METADATA_V;
12382 6 byte numscripts = 0;
12383 6 numscripts = numscripts; //to avoid unused variables warnings
12384
12385 //section id
12386
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12387 {
12388 new_return(1);
12389 }
12390
12391 //section version info
12392
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12393 {
12394 new_return(2);
12395 }
12396
12397
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12398 {
12399 new_return(3);
12400 }
12401
12402
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12403 {
12404 new_return(4);
12405 }
12406
12407
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12408 {
12409 12 fake_pack_writing=(writecycle==0);
12410
12411 //section size
12412
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12413 {
12414 new_return(5);
12415 }
12416
12417 12 writesize=0;
12418
12419
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12420 {
12421 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12422 6144 fake_pack_writing=(writecycle==0);
12423
12424
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12425 {
12426 new_return(ret);
12427 }
12428 6144 }
12429
12430
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12431 {
12432 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12433 3072 fake_pack_writing=(writecycle==0);
12434
12435
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12436 {
12437 new_return(ret);
12438 }
12439 3072 }
12440
12441
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12442 {
12443 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12444 3072 fake_pack_writing=(writecycle==0);
12445
12446
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12447 {
12448 new_return(ret);
12449 }
12450 3072 }
12451
12452
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12453
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12454 {
12455 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12456 3072 fake_pack_writing=(writecycle==0);
12457
12458
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12459 {
12460 new_return(ret);
12461 }
12462 3072 }
12463
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12464
12465
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12466 {
12467 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12468 3072 fake_pack_writing=(writecycle==0);
12469
12470
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12471 {
12472 new_return(ret);
12473 }
12474 3072 }
12475
12476
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12477 {
12478 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12479 96 fake_pack_writing=(writecycle==0);
12480
12481
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12482 {
12483 new_return(ret);
12484 }
12485 96 }
12486
12487
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12488 {
12489 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12490 60 fake_pack_writing=(writecycle==0);
12491
12492
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12493 {
12494 new_return(ret);
12495 }
12496 60 }
12497
12498
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12499 {
12500 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12501 3072 fake_pack_writing=(writecycle==0);
12502
12503
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12504 {
12505 new_return(ret);
12506 }
12507 3072 }
12508
12509
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12510 {
12511 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12512 3072 fake_pack_writing=(writecycle==0);
12513
12514
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12515 {
12516 new_return(ret);
12517 }
12518 3072 }
12519
12520
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12521 {
12522 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12523 3072 fake_pack_writing=(writecycle==0);
12524
12525
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12526 {
12527 new_return(ret);
12528 }
12529 3072 }
12530
12531
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12532 {
12533 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12534 3072 fake_pack_writing=(writecycle==0);
12535
12536
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12537 {
12538 new_return(ret);
12539 }
12540 3072 }
12541
12542
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12543 {
12544 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12545 6144 fake_pack_writing=(writecycle==0);
12546
12547
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12548 {
12549 new_return(ret);
12550 }
12551 6144 }
12552
12553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12554 {
12555 new_return(2000);
12556 }
12557
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12558 {
12559 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12560 6144 fake_pack_writing=(writecycle==0);
12561
12562
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12563 {
12564 new_return(ret);
12565 }
12566 6144 }
12567
12568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12569 {
12570 new_return(2001);
12571 }
12572
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12573 {
12574 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12575 3072 fake_pack_writing=(writecycle==0);
12576
12577
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12578 {
12579 new_return(ret);
12580 }
12581 3072 }
12582
12583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12584 {
12585 new_return(2001);
12586 }
12587
12588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12589 {
12590 new_return(2002);
12591 }
12592
12593 12 word numffcbindings=0;
12594
12595
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12596 {
12597
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12598 {
12599 200 numffcbindings++;
12600 200 }
12601 6132 }
12602
12603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12604 {
12605 new_return(2003);
12606 }
12607
12608
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12609 {
12610
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12611 {
12612
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12613 {
12614 new_return(2004);
12615 }
12616
12617
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12618 {
12619 new_return(2005);
12620 }
12621
12622
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12623 {
12624 new_return(2006);
12625 }
12626 200 }
12627 6132 }
12628
12629 12 word numglobalbindings=0;
12630
12631
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12632 {
12633
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12634 {
12635 24 numglobalbindings++;
12636 24 }
12637 96 }
12638
12639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12640 {
12641 new_return(2007);
12642 }
12643
12644
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12645 {
12646
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12647 {
12648
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12649 {
12650 new_return(2008);
12651 }
12652
12653
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12654 {
12655 new_return(2009);
12656 }
12657
12658
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12659 {
12660 new_return(2010);
12661 }
12662 24 }
12663 96 }
12664
12665 12 word numitembindings=0;
12666
12667
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12668 {
12669
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12670 {
12671 24 numitembindings++;
12672 24 }
12673 3060 }
12674
12675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12676 {
12677 new_return(2011);
12678 }
12679
12680
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12681 {
12682
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12683 {
12684
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12685 {
12686 new_return(2012);
12687 }
12688
12689
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12690 {
12691 new_return(2013);
12692 }
12693
12694
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12695 {
12696 new_return(2014);
12697 }
12698 24 }
12699 3060 }
12700
12701 //new script types
12702 //npc scripts
12703 12 word numnpcbindings=0;
12704
12705
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12706 {
12707
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12708 {
12709 numnpcbindings++;
12710 }
12711 3060 }
12712
12713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12714 {
12715 new_return(2015);
12716 }
12717
12718
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12719 {
12720
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12721 {
12722 if(!p_iputw(it->first,f))
12723 {
12724 new_return(2016);
12725 }
12726
12727 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12728 {
12729 new_return(2017);
12730 }
12731
12732 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12733 {
12734 new_return(2018);
12735 }
12736 }
12737 3060 }
12738
12739 //lweapon
12740
12741 12 word numlwpnbindings=0;
12742
12743
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12744 {
12745
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12746 {
12747 numlwpnbindings++;
12748 }
12749 3060 }
12750
12751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12752 {
12753 new_return(2019);
12754 }
12755
12756
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12757 {
12758
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12759 {
12760 if(!p_iputw(it->first,f))
12761 {
12762 new_return(2020);
12763 }
12764
12765 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12766 {
12767 new_return(2021);
12768 }
12769
12770 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12771 {
12772 new_return(2022);
12773 }
12774 }
12775 3060 }
12776
12777 //////
12778
12779 //eweapon
12780
12781
12782 12 word numewpnbindings=0;
12783
12784
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12785 {
12786
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12787 {
12788 numewpnbindings++;
12789 }
12790 3060 }
12791
12792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12793 {
12794 new_return(2023);
12795 }
12796
12797
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12798 {
12799
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12800 {
12801 if(!p_iputw(it->first,f))
12802 {
12803 new_return(2024);
12804 }
12805
12806 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12807 {
12808 new_return(2025);
12809 }
12810
12811 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12812 {
12813 new_return(2026);
12814 }
12815 }
12816 3060 }
12817
12818 //player scripts
12819 12 word numherobindings=0;
12820
12821
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12822 {
12823
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12824 {
12825 2 numherobindings++;
12826 2 }
12827 48 }
12828
12829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12830 {
12831 new_return(2027);
12832 }
12833
12834
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12835 {
12836
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12837 {
12838
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12839 {
12840 new_return(2028);
12841 }
12842
12843
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12844 {
12845 new_return(2029);
12846 }
12847
12848
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12849 {
12850 new_return(2030);
12851 }
12852 2 }
12853 48 }
12854
12855 //dmap scripts
12856 12 word numdmapbindings=0;
12857
12858
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12859 {
12860
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12861 {
12862 4 numdmapbindings++;
12863 4 }
12864 3060 }
12865
12866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12867 {
12868 new_return(2031);
12869 }
12870
12871
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12872 {
12873
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12874 {
12875
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12876 {
12877 new_return(2032);
12878 }
12879
12880
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12881 {
12882 new_return(2033);
12883 }
12884
12885
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12886 {
12887 new_return(2034);
12888 }
12889 4 }
12890 3060 }
12891
12892 //screen scripts
12893 12 word numscreenbindings=0;
12894
12895
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12896 {
12897
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12898 {
12899 16 numscreenbindings++;
12900 16 }
12901 3060 }
12902
12903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12904 {
12905 new_return(2035);
12906 }
12907
12908
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12909 {
12910
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12911 {
12912
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12913 {
12914 new_return(2036);
12915 }
12916
12917
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12918 {
12919 new_return(2037);
12920 }
12921
12922
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12923 {
12924 new_return(2038);
12925 }
12926 16 }
12927 3060 }
12928 //item sprite scripts
12929 12 word numitemspritebindings=0;
12930
12931
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12932 {
12933
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12934 {
12935 numitemspritebindings++;
12936 }
12937 3060 }
12938
12939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12940 {
12941 new_return(2039);
12942 }
12943
12944
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12945 {
12946
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12947 {
12948 if(!p_iputw(it->first,f))
12949 {
12950 new_return(2040);
12951 }
12952
12953 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12954 {
12955 new_return(2041);
12956 }
12957
12958 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12959 {
12960 new_return(2042);
12961 }
12962 }
12963 3060 }
12964
12965 //combo scripts
12966 12 word numcombobindings=0;
12967
12968
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12969 {
12970
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12971 {
12972 numcombobindings++;
12973 }
12974 6132 }
12975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12976 {
12977 new_return(2043);
12978 }
12979
12980
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12981 {
12982
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12983 {
12984 if(!p_iputw(it->first,f))
12985 {
12986 new_return(2044);
12987 }
12988
12989 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12990 {
12991 new_return(2045);
12992 }
12993
12994 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12995 {
12996 new_return(2046);
12997 }
12998 }
12999 6132 }
13000 //subscreen scripts
13001 12 word numgenericbindings=0;
13002
13003
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13004 {
13005
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13006 {
13007 numgenericbindings++;
13008 }
13009 6132 }
13010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
13011 {
13012 new_return(2043);
13013 }
13014
13015
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13016 {
13017
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13018 {
13019 if(!p_iputw(it->first,f))
13020 {
13021 new_return(2044);
13022 }
13023
13024 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13025 {
13026 new_return(2045);
13027 }
13028
13029 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13030 {
13031 new_return(2046);
13032 }
13033 }
13034 6132 }
13035
13036 //generic scripts
13037 12 word numsubscreenbindings=0;
13038
13039
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13040 {
13041
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13042 {
13043 numsubscreenbindings++;
13044 }
13045 3060 }
13046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13047 {
13048 new_return(2047);
13049 }
13050
13051
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13052 {
13053
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13054 {
13055 if(!p_iputw(it->first,f))
13056 {
13057 new_return(2048);
13058 }
13059
13060 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13061 {
13062 new_return(2049);
13063 }
13064
13065 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13066 {
13067 new_return(2050);
13068 }
13069 }
13070 3060 }
13071
13072
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13073 {
13074 6 section_size=writesize;
13075 6 }
13076 12 }
13077
13078
13079
13080
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13081 {
13082 char ebuf[80];
13083 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13084 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13085 }
13086
13087 6 new_return(0);
13088 //return 0; //this is just here to stomp the compiler from whining.
13089 //the irony is that it causes an "unreachable code" warning.
13090 6 }
13091
13092 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13093 {
13094 //these are here to bypass compiler warnings about unused arguments
13095 46236 Header=Header;
13096 46236 i=i;
13097
13098
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13099
13100
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13101 {
13102 new_return(6);
13103 }
13104
13105 //Metadata
13106 46236 zasm_meta const& tmeta = (*script)->meta;
13107
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13108 {
13109 new_return(7);
13110 }
13111
13112
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13113 {
13114 new_return(8);
13115 }
13116
13117
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13118 {
13119 new_return(9);
13120 }
13121
13122
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13123 {
13124 new_return(10);
13125 }
13126
13127
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13128 {
13129
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13130 new_return(11);
13131 369888 }
13132
13133
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13134 {
13135
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13136 {
13137 new_return(12);
13138 }
13139 369888 }
13140
13141
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13142 {
13143 new_return(13);
13144 }
13145
13146
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13147 {
13148 new_return(14);
13149 }
13150
13151
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13152 {
13153 new_return(15);
13154 }
13155
13156
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13157 {
13158 new_return(16);
13159 }
13160
13161
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13162 {
13163 new_return(17);
13164 }
13165
13166
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13167 new_return(18);
13168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13169 new_return(19);
13170
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13171 {
13172
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13173 new_return(27);
13174
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13175 new_return(28);
13176 462360 }
13177
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13178 {
13179
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13180 new_return(29);
13181
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13182 new_return(30);
13183 369888 }
13184
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13185 {
13186
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13187 new_return(31);
13188
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13189 new_return(32);
13190 369888 }
13191
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13192 {
13193
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13194 new_return(33);
13195
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13196 new_return(34);
13197 739776 }
13198
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13199 {
13200
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13201 new_return(35);
13202
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13203 new_return(36);
13204 369888 }
13205
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13206 {
13207
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13208 new_return(37);
13209 369888 }
13210
13211
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626436 times.
663178 for(int32_t j=0; j<num_commands; j++)
13212 {
13213 626436 auto& zas = (*script)->zasm_script->zasm[j];
13214
1/2
✓ Branch 0 taken 626436 times.
✗ Branch 1 not taken.
626436 if(!p_iputw(zas.command,f))
13215 {
13216 new_return(20);
13217 }
13218
13219
2/2
✓ Branch 0 taken 616942 times.
✓ Branch 1 taken 9494 times.
626436 if(zas.command==0xFFFF)
13220 {
13221 9494 break;
13222 }
13223 else
13224 {
13225
1/2
✓ Branch 0 taken 616942 times.
✗ Branch 1 not taken.
616942 if(!p_iputl(zas.arg1,f))
13226 {
13227 new_return(21);
13228 }
13229
13230
1/2
✓ Branch 0 taken 616942 times.
✗ Branch 1 not taken.
616942 if(!p_iputl(zas.arg2,f))
13231 {
13232 new_return(22);
13233 }
13234
13235
1/2
✓ Branch 0 taken 616942 times.
✗ Branch 1 not taken.
616942 if(!p_iputl(zas.arg3,f))
13236 {
13237 new_return(23);
13238 }
13239
13240 616942 uint32_t sz = 0;
13241
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614172 times.
616942 if(zas.strptr)
13242 2770 sz = zas.strptr->size();
13243
1/2
✓ Branch 0 taken 616942 times.
✗ Branch 1 not taken.
616942 if(!p_iputl(sz,f))
13244 {
13245 new_return(23);
13246 }
13247
2/2
✓ Branch 0 taken 614172 times.
✓ Branch 1 taken 2770 times.
616942 if(sz)
13248 {
13249 2770 auto& str = *zas.strptr;
13250
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13251 {
13252
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13253 {
13254 new_return(24);
13255 }
13256 222648 }
13257 2770 }
13258 616942 sz = 0;
13259
2/2
✓ Branch 0 taken 616828 times.
✓ Branch 1 taken 114 times.
616942 if(zas.vecptr)
13260 114 sz = zas.vecptr->size();
13261
1/2
✓ Branch 0 taken 616942 times.
✗ Branch 1 not taken.
616942 if(!p_iputl(sz,f))
13262 {
13263 new_return(25);
13264 }
13265
2/2
✓ Branch 0 taken 616828 times.
✓ Branch 1 taken 114 times.
616942 if(sz) //vector found
13266 {
13267 114 auto& vec = *zas.vecptr;
13268
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13269 {
13270
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13271 {
13272 new_return(26);
13273 }
13274 850 }
13275 114 }
13276 }
13277 616942 }
13278
13279 46236 new_return(0);
13280 }
13281
13282 extern SAMPLE customsfxdata[WAV_COUNT];
13283 extern uint8_t customsfxflag[WAV_COUNT>>3];
13284
13285 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13286 {
13287 //these are here to bypass compiler warnings about unused arguments
13288 6 Header=Header;
13289
13290 6 dword section_id=ID_SFX;
13291 6 dword section_version=V_SFX;
13292 6 dword section_cversion=CV_SFX;
13293 6 dword section_size=0;
13294
13295 //section id
13296
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13297 {
13298 new_return(1);
13299 }
13300
13301 //section version info
13302
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13303 {
13304 new_return(2);
13305 }
13306
13307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13308 {
13309 new_return(3);
13310 }
13311
13312
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13313 {
13314 12 fake_pack_writing=(writecycle==0);
13315
13316 //section size
13317
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13318 {
13319 new_return(4);
13320 }
13321
13322 12 writesize=0;
13323
13324
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13325 {
13326
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13327 {
13328 new_return(5);
13329 }
13330 384 }
13331
13332
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13333 {
13334
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13335 2240 continue;
13336
13337
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13338 {
13339 new_return(5);
13340 }
13341 820 }
13342
13343
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13344 {
13345
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13346 2240 continue;
13347
13348
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13349 {
13350 new_return(5);
13351 }
13352
13353
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13354 {
13355 new_return(6);
13356 }
13357
13358
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13359 {
13360 new_return(7);
13361 }
13362
13363
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13364 {
13365 new_return(8);
13366 }
13367
13368
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13369 {
13370 new_return(9);
13371 }
13372
13373
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13374 {
13375 new_return(10);
13376 }
13377
13378
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13379 {
13380 new_return(11);
13381 }
13382
13383
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13384 {
13385 new_return(12);
13386 }
13387
13388 //de-endianfy the data
13389 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13390
13391
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13392 {
13393
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13394 {
13395 new_return(13);
13396 }
13397 18594894 }
13398 820 }
13399
13400
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13401 {
13402 6 section_size=writesize;
13403 6 }
13404 12 }
13405
13406
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13407 {
13408 char ebuf[80];
13409 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13410 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13411 }
13412
13413 6 new_return(0);
13414 }
13415
13416 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13417 {
13418 6 dword section_id=ID_INITDATA;
13419 6 dword section_version=V_INITDATA;
13420 6 dword section_cversion=CV_INITDATA;
13421 6 dword section_size = 0;
13422
13423 6 zinit.last_map=Map.getCurrMap();
13424 6 zinit.last_screen=Map.getCurrScr();
13425 6 zinit.normalize();
13426
13427 //section id
13428
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13429 {
13430 new_return(1);
13431 }
13432
13433 //section version info
13434
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13435 {
13436 new_return(2);
13437 }
13438
13439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13440 {
13441 new_return(3);
13442 }
13443
13444 //TODO
13445
13446
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13447 {
13448 12 fake_pack_writing=(writecycle==0);
13449
13450 //section size
13451
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13452 new_return(4);
13453
13454 12 writesize=0;
13455
13456
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13457
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13458 new_return(5);
13459
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13460 {
13461
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13462 new_return(6);
13463
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13464 new_return(7);
13465
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13466 new_return(8);
13467
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13468 new_return(9);
13469 768 }
13470
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13471 new_return(10);
13472
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13473 new_return(11);
13474
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13475
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13476 new_return(12);
13477
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13478
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13479 new_return(13);
13480
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13481 new_return(14);
13482
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13483 new_return(15);
13484
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13485 new_return(16);
13486
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13487 new_return(17);
13488
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13489 new_return(18);
13490
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13491 new_return(19);
13492
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13493 new_return(20);
13494
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13495 new_return(21);
13496
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13497 new_return(22);
13498
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13499 new_return(23);
13500
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13501 new_return(24);
13502
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13503 new_return(25);
13504
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13505 new_return(26);
13506
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13507 new_return(27);
13508
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13509 new_return(28);
13510
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13511 new_return(29);
13512
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13513 new_return(30);
13514
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13515 new_return(31);
13516
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13517 new_return(32);
13518
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13519 new_return(33);
13520
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13521 new_return(34);
13522
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13523 new_return(35);
13524
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13525 new_return(36);
13526
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13527 new_return(37);
13528
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13529 new_return(38);
13530
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13531 new_return(39);
13532
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13533 new_return(40);
13534
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13535 new_return(41);
13536
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13537 new_return(42);
13538
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13539 new_return(43);
13540
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13541 new_return(44);
13542
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13543 new_return(45);
13544
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13545 new_return(46);
13546
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13547 new_return(47);
13548
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13549 new_return(48);
13550
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13551 new_return(49);
13552
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13553 new_return(50);
13554
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13555 new_return(51);
13556
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13557 new_return(52);
13558
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13559 new_return(53);
13560
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13561 new_return(54);
13562
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13563 new_return(55);
13564
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13565 new_return(56);
13566
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13567 new_return(57);
13568
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13569 new_return(58);
13570
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13571 new_return(59);
13572
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13573 new_return(60);
13574
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13575 new_return(61);
13576
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13577 new_return(62);
13578
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13579 new_return(63);
13580
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13581 new_return(64);
13582
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13583 new_return(65);
13584
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13585 new_return(66);
13586
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13587 new_return(67);
13588
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13589 new_return(68);
13590
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13591 new_return(69);
13592
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13593 new_return(70);
13594
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13595 new_return(71);
13596
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13597 new_return(72);
13598
13599
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13600 {
13601 6 section_size=writesize;
13602 6 }
13603 12 }
13604
13605
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13606 {
13607 char ebuf[80];
13608 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13609 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13610 }
13611
13612 6 new_return(0);
13613 }
13614
13615 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13616 {
13617 //these are here to bypass compiler warnings about unused arguments
13618 6 Header=Header;
13619
13620 6 dword section_id=ID_ITEMDROPSETS;
13621 6 dword section_version=V_ITEMDROPSETS;
13622 6 dword section_cversion=CV_ITEMDROPSETS;
13623 // dword section_size=0;
13624 6 dword section_size = 0;
13625 6 word num_item_drop_sets=count_item_drop_sets();
13626
13627 //section id
13628
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13629 {
13630 new_return(1);
13631 }
13632
13633 //section version info
13634
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13635 {
13636 new_return(2);
13637 }
13638
13639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13640 {
13641 new_return(3);
13642 }
13643
13644
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13645 {
13646 12 fake_pack_writing=(writecycle==0);
13647
13648 //section size
13649
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13650 {
13651 new_return(4);
13652 }
13653
13654 12 writesize=0;
13655
13656 //finally... section data
13657
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13658 {
13659 new_return(5);
13660 }
13661
13662
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13663 {
13664
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13665 {
13666 new_return(6);
13667 }
13668
13669
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13670 {
13671
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13672 {
13673 new_return(7);
13674 }
13675 1580 }
13676
13677
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13678 {
13679
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13680 {
13681 new_return(8);
13682 }
13683 1738 }
13684 158 }
13685
13686
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13687 {
13688 6 section_size=writesize;
13689 6 }
13690 12 }
13691
13692
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13693 {
13694 char ebuf[80];
13695 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13696 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13697 }
13698
13699 6 new_return(0);
13700 }
13701
13702 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13703 {
13704 6 dword section_id=ID_FAVORITES;
13705 6 dword section_version=V_FAVORITES;
13706 6 dword section_cversion=CV_FAVORITES;
13707 6 dword section_size = 0;
13708
13709 //section id
13710
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13711 {
13712 new_return(1);
13713 }
13714
13715 //section version info
13716
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13717 {
13718 new_return(2);
13719 }
13720
13721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13722 {
13723 new_return(3);
13724 }
13725
13726
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13727 {
13728 12 fake_pack_writing=(writecycle==0);
13729
13730 //section size
13731
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13732 new_return(4);
13733
13734 12 writesize=0;
13735
13736
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13737 new_return(16);
13738
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13739 new_return(17);
13740
13741 12 word favcmb_cnt = 0;
13742
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13743
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13744 {
13745 8 favcmb_cnt = q+1;
13746 8 break;
13747 }
13748
13749
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13750 new_return(5);
13751
13752
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13753 {
13754
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13755 new_return(6);
13756
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13757 new_return(7);
13758 210 }
13759
13760
13761 12 word max_combo_cols = MAX_COMBO_COLS;
13762
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13763 new_return(9);
13764
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13765 {
13766
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13767 new_return(10);
13768
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13769 new_return(11);
13770
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13771 new_return(12);
13772 48 }
13773 12 word max_mappages = MAX_MAPPAGE_BTNS;
13774
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13775 new_return(13);
13776
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13777 {
13778
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13779 new_return(14);
13780
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13781 new_return(15);
13782 108 }
13783
13784
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13785 {
13786 6 section_size=writesize;
13787 6 }
13788 12 }
13789
13790
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13791 {
13792 char ebuf[80];
13793 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13794 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13795 }
13796
13797 6 new_return(0);
13798 }
13799
13800 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13801 {
13802
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13803 6 reset_combo_animations();
13804 6 reset_combo_animations2();
13805 6 strcpy(header.id_str,QH_NEWIDSTR);
13806 6 header.zelda_version = ZELDA_VERSION;
13807 6 header.internal = INTERNAL_VERSION;
13808 // header.str_count = msg_count;
13809 // header.data_flags[ZQ_TILES] = usetiles;
13810 6 header.data_flags[ZQ_TILES] = true;
13811 6 header.data_flags[ZQ_CHEATS2] = 1;
13812 6 header.build=VERSION_BUILD;
13813
13814
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13815 {
13816 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13817 1512 }
13818
13819 char zinfofilename[2048];
13820 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13821
13822 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13823 6 box_out("Saving Quest...");
13824 6 box_eol();
13825 6 box_eol();
13826
13827
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13828
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13829
13830
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13831 return 1;
13832
13833
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13834
13835
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13836 return 2;
13837
13838
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13839
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13840
13841
13842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13843 {
13844 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13845
13846 box_out("Writing ZInfo...");
13847 if(inf)
13848 {
13849 if(writezinfo(inf,ZI)!=0)
13850 return 2;
13851
13852 pack_fclose(inf);
13853 box_out("okay.");
13854 }
13855 else box_out(" ...file failure");
13856 box_eol();
13857 }
13858 else
13859 {
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13861
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13862 return 2;
13863
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13864
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13865 }
13866
13867
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13869
13870
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13871 return 3;
13872
13873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13874
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13875
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13877
13878
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13879 return 4;
13880
13881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13882
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13883
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13885
13886
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13887 return 5;
13888
13889
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13890
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13891
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13893
13894
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13895 return 6;
13896
13897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13898
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13899
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13901
13902
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13903 return 7;
13904
13905
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13906
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13907
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13909
13910
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13911 return 8;
13912
13913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13914
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13915
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13917
13918
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13919 return 9;
13920
13921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13923
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13925
13926
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13927 return 10;
13928
13929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13930
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13931
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13933
13934
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13935 return 11;
13936
13937
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13938
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13939
13940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13941
13942
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13943 return 12;
13944
13945
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13946
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13947
13948
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13949
13950
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13951 return 13;
13952
13953
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13954
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13955
13956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13957
13958
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13959 return 14;
13960
13961
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13963
13964
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13965
13966
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13967 return 15;
13968
13969
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13970
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13971
13972
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13973
13974
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13975 return 16;
13976
13977
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13978
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13979
13980
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13981
13982
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13983 return 17;
13984
13985
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13986
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13987
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13989
13990
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13991 return 18;
13992
13993
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13994
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13995
13996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13997
13998
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13999 return 19;
14000
14001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14003
14004
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
14005
14006
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
14007 return 20;
14008
14009
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14010
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14011
14012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
14013
14014
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
14015 return 21;
14016
14017
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14018
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14019
14020
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
14021
14022
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14023 return 22;
14024
14025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14026
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14027
14028
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14029
14030
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14031 return 23;
14032
14033
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14034
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14035
14036
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14037
14038
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14039 return 24;
14040
14041
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14042
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14043
14044
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14045
14046
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14047 return 25;
14048
14049
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14050
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14051
14052
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14053
14054
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14055 return 26;
14056
14057
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14058
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14059
14060
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14061
14062
14063
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14064 {
14065 char const* kfname = filename;
14066 char keyfilename[2048]={0};
14067 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14068
14069 char temp_pw[QSTPWD_LEN] = {0};
14070 uint ind = 0;
14071 for(char const* ext : {"key","zpwd","zcheat"})
14072 {
14073 replace_extension(keyfilename, kfname, ext, 2047);
14074 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14075 char msg[80] = {0};
14076 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14077 msg[78]=13;
14078 msg[79]=10;
14079 pfwrite(msg, 80, fp);
14080 p_iputw(header.zelda_version,fp);
14081 p_putc(header.build,fp);
14082 char const* pwd = header.password;
14083 if(ind == 2) //.zcheat, hashed pwd
14084 {
14085 char hashmap = 'Z';
14086 hashmap += 'Q';
14087 hashmap += 'U';
14088 hashmap += 'E';
14089 hashmap += 'S';
14090 hashmap += 'T';
14091 for ( int q = 0; q < QSTPWD_LEN; ++q )
14092 {
14093 temp_pw[q] = header.password[q];
14094 temp_pw[q] += hashmap;
14095 }
14096 pwd = temp_pw;
14097 }
14098 pfwrite(pwd, strlen(pwd), fp);
14099 pack_fclose(fp);
14100 ++ind;
14101 }
14102 }
14103
14104 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14105 6 std::error_code ec;
14106
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14108 {
14109 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14110 return ec.value();
14111 }
14112
14113
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14114
14115 #ifdef __EMSCRIPTEN__
14116 em_sync_fs();
14117 #endif
14118
14119 6 return 0;
14120 6 }
14121
14122 // #ifdef _WIN32
14123 // static std::time_t to_time_t(FILETIME const& ft) {
14124 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14125 // t -= 116444736000000000ull;
14126 // t /= 10000000u;
14127 // return static_cast<std::time_t>(t);
14128 // }
14129 // #else
14130 // #endif
14131 template<typename TP>
14132 4 static std::time_t to_time_t(TP tp) {
14133 using namespace std::chrono;
14134 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14135 4 return system_clock::to_time_t(sctp);
14136 }
14137
14138 4 std::string get_time_last_modified_string(std::string path)
14139 {
14140
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14141 // TODO: C++20 but not supported yet.
14142 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14143 4 std::time_t tt = to_time_t(write_time);
14144 4 std::tm *gmt = std::gmtime(&tt);
14145 4 std::stringstream buffer;
14146
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14147
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14148 4 return formattedFileTime;
14149
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14150
14151 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14152 {
14153 // Always backup quest if it was last saved in a different version of the editor,
14154 // or if this a new file and is overwritting another qst file.
14155
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14156 {
14157 4 std::string backup_name;
14158
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14159
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14160 {
14161
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14162 4 }
14163 else
14164 {
14165 backup_name = fmt::format("{}", last_mod);
14166 }
14167
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14168
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14169
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14170 {
14171
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14172
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14173 {
14174
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14175 4 }
14176 else
14177 {
14178 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14179 }
14180 4 }
14181 4 }
14182
14183 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14184 6 fake_pack_writing = false;
14185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14186 {
14187 box_out("-- Error saving quest file! --");
14188 box_end(true);
14189 }
14190 6 else box_end(false);
14191 6 return ret;
14192 }
14193
14194 6 int32_t save_quest(const char *filename, bool timed_save)
14195 {
14196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14197
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14198 char ext1[5];
14199 6 ext1[0]=0;
14200
14201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14202 {
14203 sprintf(ext1, "qt");
14204 }
14205 else
14206 {
14207 6 sprintf(ext1, "qb");
14208 }
14209
14210
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14211 {
14212 char backupname[2048];
14213 char backupname2[2048];
14214 char ext[12];
14215
14216 for(int32_t i=retention-1; i>0; --i)
14217 {
14218 sprintf(ext, "%s%d", ext1, i-1);
14219 replace_extension(backupname, filepath, ext, 2047);
14220
14221 if(exists(backupname))
14222 {
14223 sprintf(ext, "%s%d", ext1, i);
14224 replace_extension(backupname2, filepath, ext, 2047);
14225
14226 if(exists(backupname2))
14227 {
14228 remove(backupname2);
14229 }
14230
14231 rename(backupname, backupname2);
14232 }
14233 }
14234
14235 //don't do this if we're not saving to the same name -DD
14236 if(!timed_save && !strcmp(filepath, filename))
14237 {
14238 sprintf(ext, "%s%d", ext1, 0);
14239 replace_extension(backupname, filepath, ext, 2047);
14240 rename(filepath, backupname);
14241 }
14242 }
14243
14244 int32_t ret;
14245 6 ret = save_unencoded_quest(filename, compress, filename);
14246
14247 6 return ret;
14248 }
14249
14250 6 void center_zq_class_dialogs()
14251 {
14252 6 jwin_center_dialog(pwd_dlg);
14253 6 }
14254
14255 void zmap::prv_secrets(bool high16only)
14256 {
14257 mapscr *s = &prvscr;
14258 mapscr *t = prvlayers;
14259 int32_t ft=0;
14260
14261 for(int32_t i=0; i<176; i++)
14262 {
14263 bool putit;
14264
14265 if(!high16only)
14266 {
14267 for(int32_t j=-1; j<6; j++)
14268 {
14269 int32_t newflag = -1;
14270
14271 for(int32_t iter=0; iter<2; ++iter)
14272 {
14273 putit=true;
14274
14275 if(!t[j].valid)
14276 continue;
14277
14278 int32_t checkflag=combobuf[t[j].data[i]].flag;
14279
14280 if(iter==1)
14281 {
14282 checkflag=t[j].sflag[i];
14283 }
14284
14285 switch(checkflag)
14286 {
14287 case mfANYFIRE:
14288 ft=sBCANDLE;
14289 break;
14290
14291 case mfSTRONGFIRE:
14292 ft=sRCANDLE;
14293 break;
14294
14295 case mfMAGICFIRE:
14296 ft=sWANDFIRE;
14297 break;
14298
14299 case mfDIVINEFIRE:
14300 ft=sDIVINEFIRE;
14301 break;
14302
14303 case mfARROW:
14304 ft=sARROW;
14305 break;
14306
14307 case mfSARROW:
14308 ft=sSARROW;
14309 break;
14310
14311 case mfGARROW:
14312 ft=sGARROW;
14313 break;
14314
14315 case mfSBOMB:
14316 ft=sSBOMB;
14317 break;
14318
14319 case mfBOMB:
14320 ft=sBOMB;
14321 break;
14322
14323 case mfBRANG:
14324 ft=sBRANG;
14325 break;
14326
14327 case mfMBRANG:
14328 ft=sMBRANG;
14329 break;
14330
14331 case mfFBRANG:
14332 ft=sFBRANG;
14333 break;
14334
14335 case mfWANDMAGIC:
14336 ft=sWANDMAGIC;
14337 break;
14338
14339 case mfREFMAGIC:
14340 ft=sREFMAGIC;
14341 break;
14342
14343 case mfREFFIREBALL:
14344 ft=sREFFIREBALL;
14345 break;
14346
14347 case mfSWORD:
14348 ft=sSWORD;
14349 break;
14350
14351 case mfWSWORD:
14352 ft=sWSWORD;
14353 break;
14354
14355 case mfMSWORD:
14356 ft=sMSWORD;
14357 break;
14358
14359 case mfXSWORD:
14360 ft=sXSWORD;
14361 break;
14362
14363 case mfSWORDBEAM:
14364 ft=sSWORDBEAM;
14365 break;
14366
14367 case mfWSWORDBEAM:
14368 ft=sWSWORDBEAM;
14369 break;
14370
14371 case mfMSWORDBEAM:
14372 ft=sMSWORDBEAM;
14373 break;
14374
14375 case mfXSWORDBEAM:
14376 ft=sXSWORDBEAM;
14377 break;
14378
14379 case mfHOOKSHOT:
14380 ft=sHOOKSHOT;
14381 break;
14382
14383 case mfWAND:
14384 ft=sWAND;
14385 break;
14386
14387 case mfHAMMER:
14388 ft=sHAMMER;
14389 break;
14390
14391 case mfSTRIKE:
14392 ft=sSTRIKE;
14393 break;
14394
14395 default:
14396 putit = false;
14397 break;
14398 }
14399
14400 if(putit)
14401 {
14402 if(j==-1)
14403 {
14404 s->data[i] = s->secretcombo[ft];
14405 s->cset[i] = s->secretcset[ft];
14406 newflag = s->secretflag[ft];
14407 }
14408 else
14409 {
14410 t[j].data[i] = t[j].secretcombo[ft];
14411 t[j].cset[i] = t[j].secretcset[ft];
14412 newflag = t[j].secretflag[ft];
14413 }
14414 }
14415 }
14416
14417 if(newflag >-1)
14418 {
14419 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14420 }
14421 }
14422 }
14423
14424 //if(true)
14425 //{
14426 int32_t newflag = -1;
14427
14428 for(int32_t iter=0; iter<2; ++iter)
14429 {
14430 int32_t checkflag=combobuf[s->data[i]].flag;
14431
14432 if(iter==1)
14433 {
14434 checkflag=s->sflag[i];
14435 }
14436
14437 if((checkflag > 15)&&(checkflag < 32))
14438 {
14439 s->data[i] = s->secretcombo[(checkflag)-16+4];
14440 s->cset[i] = s->secretcset[(checkflag)-16+4];
14441 newflag = s->secretflag[(checkflag)-16+4];
14442 // putit = true;
14443 }
14444 }
14445
14446 if(newflag >-1) s->sflag[i] = newflag;
14447
14448 for(int32_t j=0; j<6; j++)
14449 {
14450 if(!t[j].valid) continue;
14451
14452 int32_t newflag2 = -1;
14453
14454 for(int32_t iter=0; iter<2; ++iter)
14455 {
14456 int32_t checkflag=combobuf[t[j].data[i]].flag;
14457
14458 if(iter==1)
14459 {
14460 checkflag=t[j].sflag[i];
14461 }
14462
14463 if((checkflag > 15)&&(checkflag < 32))
14464 {
14465 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14466 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14467 newflag2 = t[j].secretflag[(checkflag)-16+4];
14468 }
14469 }
14470
14471 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14472 }
14473 }
14474
14475 //FFCs
14476 word c = s->numFFC();
14477 for(word i=0; i<c; ++i)
14478 {
14479 bool putit;
14480
14481 if(!high16only)
14482 {
14483 for(int32_t iter=0; iter<1; ++iter)
14484 {
14485 putit=true;
14486 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14487
14488 if(iter==1)
14489 {
14490 checkflag=s->sflag[i];
14491 }
14492
14493 switch(checkflag)
14494 {
14495 case mfANYFIRE:
14496 ft=sBCANDLE;
14497 break;
14498
14499 case mfSTRONGFIRE:
14500 ft=sRCANDLE;
14501 break;
14502
14503 case mfMAGICFIRE:
14504 ft=sWANDFIRE;
14505 break;
14506
14507 case mfDIVINEFIRE:
14508 ft=sDIVINEFIRE;
14509 break;
14510
14511 case mfARROW:
14512 ft=sARROW;
14513 break;
14514
14515 case mfSARROW:
14516 ft=sSARROW;
14517 break;
14518
14519 case mfGARROW:
14520 ft=sGARROW;
14521 break;
14522
14523 case mfSBOMB:
14524 ft=sSBOMB;
14525 break;
14526
14527 case mfBOMB:
14528 ft=sBOMB;
14529 break;
14530
14531 case mfBRANG:
14532 ft=sBRANG;
14533 break;
14534
14535 case mfMBRANG:
14536 ft=sMBRANG;
14537 break;
14538
14539 case mfFBRANG:
14540 ft=sFBRANG;
14541 break;
14542
14543 case mfWANDMAGIC:
14544 ft=sWANDMAGIC;
14545 break;
14546
14547 case mfREFMAGIC:
14548 ft=sREFMAGIC;
14549 break;
14550
14551 case mfREFFIREBALL:
14552 ft=sREFFIREBALL;
14553 break;
14554
14555 case mfSWORD:
14556 ft=sSWORD;
14557 break;
14558
14559 case mfWSWORD:
14560 ft=sWSWORD;
14561 break;
14562
14563 case mfMSWORD:
14564 ft=sMSWORD;
14565 break;
14566
14567 case mfXSWORD:
14568 ft=sXSWORD;
14569 break;
14570
14571 case mfSWORDBEAM:
14572 ft=sSWORDBEAM;
14573 break;
14574
14575 case mfWSWORDBEAM:
14576 ft=sWSWORDBEAM;
14577 break;
14578
14579 case mfMSWORDBEAM:
14580 ft=sMSWORDBEAM;
14581 break;
14582
14583 case mfXSWORDBEAM:
14584 ft=sXSWORDBEAM;
14585 break;
14586
14587 case mfHOOKSHOT:
14588 ft=sHOOKSHOT;
14589 break;
14590
14591 case mfWAND:
14592 ft=sWAND;
14593 break;
14594
14595 case mfHAMMER:
14596 ft=sHAMMER;
14597 break;
14598
14599 case mfSTRIKE:
14600 ft=sSTRIKE;
14601 break;
14602
14603 default:
14604 putit = false;
14605 break;
14606 }
14607
14608 if(putit)
14609 {
14610 s->ffcs[i].data = s->secretcombo[ft];
14611 s->ffcs[i].cset = s->secretcset[ft];
14612 }
14613 }
14614 }
14615
14616 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14617 {
14618 for(int32_t iter=0; iter<1; ++iter)
14619 {
14620 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14621
14622 if(iter==1)
14623 {
14624 // FFCs can't have flags! Yet...
14625 }
14626
14627 if((checkflag > 15)&&(checkflag < 32))
14628 {
14629 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14630 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14631 // putit = true;
14632 }
14633 }
14634 }
14635 }
14636 }
14637